Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 11th, 2006, 11:39 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,565 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 8 h 50 m 47 sec
Reputation Power: 379
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Ruby Or Python

I dont know if this has been posted before... but.. i wanted to know... if it is worth learning ruby or python first? i mean.. i know some pythong... and i actually never tried ruby yet.. but what are the advantages of me learning ruby?

Reply With Quote
  #2  
Old March 12th, 2006, 03:38 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,565 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 8 h 50 m 47 sec
Reputation Power: 379
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Fine then.. i will stick with python

Reply With Quote
  #3  
Old March 12th, 2006, 08:56 PM
SimonGreenhill's Avatar
SimonGreenhill SimonGreenhill is offline
(retired)
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Dec 2003
Location: The Laboratory
Posts: 10,101 SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)  Folding Points: 4925 Folding Title: Novice Folder
Time spent in forums: 3 Months 3 Weeks 5 h 56 m 41 sec
Reputation Power: 1345
Facebook
I was waiting for this question to start a flamewar. How boring

Oh well, here I go: in my opinion, Python is far more useful than Ruby because it's got the libraries, it's got the large developer community, in short - it's USEFUL. The only thing Ruby is used for at the moment is Ruby on Rails.

HOWEVER - I'm not saying that Ruby is crap - far from it ( although I DO get sick of ROR fanboys ), and learning a new language is always a good thing. For that matter, I think both Ruby and Python are very similar in syntax and in design principles, and aren't terribly different at all.

--Simon

Reply With Quote
  #4  
Old March 12th, 2006, 10:10 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,565 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 8 h 50 m 47 sec
Reputation Power: 379
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Quote:
Originally Posted by SimonGreenhill
I was waiting for this question to start a flamewar. How boring

--Simon
Hehe how evil... its probably because they all know that i never tried ruby before.. or never actually seened it in action ( that i know of ) but.. thanx... my last decision was py , although the flame war would of been good hehe

Reply With Quote
  #5  
Old March 13th, 2006, 12:48 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 30 m 28 sec
Reputation Power: 1025
disagree. not going to start a flamewar about it but even in the core ruby libraries there's enough to make python jealous.

and there's something about being able to read and process a file in one line that's kinda cool
Comments on this post
netytan agrees!

Reply With Quote
  #6  
Old March 13th, 2006, 01:14 AM
SimonGreenhill's Avatar
SimonGreenhill SimonGreenhill is offline
(retired)
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Dec 2003
Location: The Laboratory
Posts: 10,101 SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)  Folding Points: 4925 Folding Title: Novice Folder
Time spent in forums: 3 Months 3 Weeks 5 h 56 m 41 sec
Reputation Power: 1345
Facebook
I'm sure you could write an entire operating system in a perl one-liner. This does not mean that it's cool ( well THAT would be, but LOC counts are not a good indicator of readability or power of language ). For that matter, I'm sure I could do the same in python, by using the ; .

So - sell Ruby. What does Ruby do better?

-Simon
Comments on this post
Yawmark agrees!
netytan agrees!

Reply With Quote
  #7  
Old March 13th, 2006, 01:20 AM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,565 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 8 h 50 m 47 sec
Reputation Power: 379
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Quote:
Originally Posted by SimonGreenhill
So - sell Ruby. What does Ruby do better?
-Simon

thats what i want to know

Reply With Quote
  #8  
Old March 13th, 2006, 02:38 AM
theBlackDragon's Avatar
theBlackDragon theBlackDragon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Zomergem (Belgium)
Posts: 145 theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 2139 Folding Title: Novice Folder
Time spent in forums: 1 Day 17 h 14 m 38 sec
Reputation Power: 16
Send a message via ICQ to theBlackDragon Send a message via AIM to theBlackDragon Send a message via Yahoo to theBlackDragon
I've been in the same position as you and I decided to learn whichever I found a good book for first. Which ended up being Python. But still, while Python has a lot of good stuff I like Ruby's syntax more, it's cleaner and more readable imho so I ended up gong back and trying to learn Ruby ...

Also I like Ruby's documentation better, even though there's less of it what there is is written in a much clearer fashion leaving for less time wasted trying to figure out how some method works.

Python's integration with GTK is in fact what drove me back to Ruby, the way Python structures this GUI code feels just plain awkward to me, the way ruby deals with it felt quite a bit more natural...

(I'm not talking about ROR, I've never used that, nor do I really intend to)

All of this is my own opinion though. But honestly I'd take a look at both and see which one you like best, they're not that hard to learn if you have a little bit of time

Reply With Quote
  #9  
Old March 13th, 2006, 10:58 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 30 m 28 sec
Reputation Power: 1025
ruby? i'll sell it

Say you've got to process a file, you'd do it like this in perl (my python sucks, you don't wanna see it)

open(INFILE,"</path/to/file");
while (<INFILE>) {print $_;}
close INFILE;

or something similar.

In ruby

File("/path/to/file") {|x| puts x}

now understand that's a grossly simplified example. But note that it takes care of allocating and deallocating the filehandle for you.

Now let's try some string manipulation...

We have inline regexps, perl style, lovely, unlike ****ing with the python regexp objects.

x =~ /([a-z]+)/
print $1;

something like that. Saves a lot of time over the python version

Then there's all the lovely methods attached to objects

puts "blah".reverse
print ("2122".reverse.to_i - 100)

see that, i reversed it and then converted it to an integer, all in one statement. quick and easier to follow

The classes that come with ruby are more logical and easier to use, and they have a lot of nice functionality, and many shortcuts. An example is the Marshal class. Being a python god you'll know all about saving dictionaries to file, i presume. Well the marshal class saves any object in a marshalled form that you can get easy access to. Imagine sending it over the net and being able to take it apart again nicely Well it's a good example

require 'Marshal'
marshalledhash = Marshal(myhash)

now, we could have passed in a second parameter, filename, which would save us writing this to file, since that's one of the common things you want to do with marshalled objects. Every core class is like this, and other classes try to be like this. An example is ruby-gnome2, which is ridiculously easy to use. Cool, I swear.

Ruby also excels when it comes to hashes (dictionaries) and lists (arrays).

Try this for size

{x=>5,y=>8,z=>9}.each {|x,y| print "#{x} = #{y}"}

that #{} business was interpolation, btw, interpolating the variables into the string.

other methods on hashes include the standard python kit i suppose, keys, values, etc.

what python doesn't allow you to do is construct a simple loop like that with a passed in lamda (the block in brackets is a lambda function, called a block that is activated within the class in a special way). python's lambdas really suck ***, only allowed to be one statement and all... Try this for size

myarray.each do |x|
x.chop!
print x[4]
end

That was two statements, counting as a block too, and i could have done more. And you'll also notice i used array notation on a string. that gets the character at that position, like you'd use on a python list to get a member. you can also use the python syntax to get a subset of the results

x[1...3]

x[-3...-1]

etc.

there are just so many neat things built in, y'know...

creating your own functions that accept blocks is easy too

def myfunc (x,y)
yield #This is what calls the optional lambda block there.
end

if it suits you, you CAN also pass a lambda directly as an argument if that's what the function expects

myfunc(x, lambda {|x| puts x})

but seriously, me talking about it won't do a thing to convince you, you've gotta try it to know.

Reply With Quote
  #10  
Old March 13th, 2006, 11:09 AM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,565 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 8 h 50 m 47 sec
Reputation Power: 379
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Quote:
Originally Posted by LinuxPenguin

File("/path/to/file") {|x| puts x}

now understand that's a grossly simplified example.
Yes it is lol

Reply With Quote
  #11  
Old March 13th, 2006, 11:41 PM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 750 L7Sqr User rank is First Lieutenant (10000 - 20000 Reputation Level)L7Sqr User rank is First Lieutenant (10000 - 20000 Reputation Level)L7Sqr User rank is First Lieutenant (10000 - 20000 Reputation Level)L7Sqr User rank is First Lieutenant (10000 - 20000 Reputation Level)L7Sqr User rank is First Lieutenant (10000 - 20000 Reputation Level)L7Sqr User rank is First Lieutenant (10000 - 20000 Reputation Level)L7Sqr User rank is First Lieutenant (10000 - 20000 Reputation Level)L7Sqr User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 15 h 47 m 10 sec
Reputation Power: 181
Send a message via AIM to L7Sqr
You may want to consider that python (by design) does not provide protected/private data members - ruby does.
And since it has been mentioned, if you are familiar at all with perl, the transition to ruby may be easier on you: Ruby supports the $_ and such global variables used in mostly the same way (although it is depreciated).

Both ruby and python are capable of / do mostly the same things and have similar (not very similar) ideas. They are both fully object oriented. They both provide internal unit testing. They both present a much cleaner approach to learing a programming language (as compared to something like C).

Ruby has a more flexible syntax. Python has a larger user/support base, but ruby is growing steadily. For current web development, ruby might do you better.

As far as performance, they are about equal and each have internal packages/libraries for testing and monitoring this performance.

Learning each will not make you more qualified at anything per se, as you will still need to use your brain to figure out the problems before implementing the solution.

My suggestion is to try both, see what fits you best and learn that fully. Do not, however, disregard the other as it is always helpful to have another card up your sleave.
__________________
Some people have 20 years of experience. Some have 1 year of experience 20 times.

My personal site: Basic geek randomness

Reply With Quote
  #12  
Old March 14th, 2006, 04:57 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,420 DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level)DevCoach User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 19 h 15 m 30 sec
Reputation Power: 797
Here is a comparison of LinuxPenguins examples and the Python equivalent.

Quote:
Originally Posted by LinuxPenguin
File("/path/to/file") {|x| puts x}


python Code:
Original - python Code
  1. for x in open("/path/to/file"): print x


Quote:
Originally Posted by LinuxPenguin
x =~ /([a-z]+)/
print $1;


python Code:
Original - python Code
  1. import re
  2. match = re.search("([a-z]+)")
  3. print match.group(1)


This is a little more verbose since Python does not have the perl-style $ variables that are set as a side effect of certain operations. However I have read that these are now regarded as bad style in the Ruby community and may be removed in Ruby 2.0.

Quote:
Originally Posted by LinuxPenguin
puts "blah".reverse
print ("2122".reverse.to_i - 100)


python Code:
Original - python Code
  1. print int("2122".reverse())


Quote:
Originally Posted by LinuxPenguin
require 'Marshal'
marshalledhash = Marshal(myhash)

The pickle module does the same thing:

python Code:
Original - python Code
  1. import pickle
  2. # save object to a file
  3. pickle.dump(object, filename)
  4. # create a pickled object in a string
  5. pickledObj = pickle.dumps(object)


Pickle will work with pretty much any type of Python object, just like Marshal.

Quote:
Originally Posted by LinuxPenguin
{x=>5,y=>8,z=>9}.each {|x,y| print "#{x} = #{y}"}


python Code:
Original - python Code
  1. for (x,y) in {'x':5, 'y':8, 'z':9}.items(): print '%s = %s' % (x, y)


Quote:
Originally Posted by LinuxPenguin
myarray.each do |x|
x.chop!
print x[4]
end


python Code:
Original - python Code
  1. for x in myarray:
  2.    x = x.rstrip()
  3.    print x[4]

[/QUOTE]


Quote:
Originally Posted by LinuxPenguin

def myfunc (x,y)
yield #This is what calls the optional lambda block there.
end


Python generators provide roughly similar functionality, but in a different way. Generators yield a sequence of values that can be passed to a block of code in a for loop. Generators are currently less powerful that ruby blocks since the information can only go from the generator to the block, and not back the other way. This will be fixed in the next version of Python.


Dave
Comments on this post
Yawmark agrees: Nice examples.
xlordt agrees: I guess your back from the dead heh
Dietrich agrees: Python is right up there, and easier to read than Ruby!
LinuxPenguin agrees: Not bad at all, although you're still missing some bits
netytan agrees: It's a personal choice .

Last edited by DevCoach : March 14th, 2006 at 05:01 AM. Reason: added code highlight tags

Reply With Quote
  #13  
Old March 15th, 2006, 07:33 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 30 m 28 sec
Reputation Power: 1025
ruby beats python on iterating though each character in a string, i don't think python has a really simple way of doing that.

ruby: "blah".each_char {|ch| puts ch.ljust(500)}

The classes in python don't have protected and private members in python either, which is a pain, and your use of the pickle class shows that it isn't quite as simple as the ruby one, where you get an optional parameter for filename. If it's provided, it writes to file, if not it returns a string, but in yours, you have to use another function.

Don't get me wrong, python's an alright language, and the if-name-main trick looks like crap in ruby, but i prefer ruby overall

Reply With Quote
  #14  
Old March 15th, 2006, 11:41 PM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 310 Dietrich User rank is Sergeant (500 - 2000 Reputation Level)Dietrich User rank is Sergeant (500 - 2000 Reputation Level)Dietrich User rank is Sergeant (500 - 2000 Reputation Level)Dietrich User rank is Sergeant (500 - 2000 Reputation Level)Dietrich User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 6 m 2 sec
Reputation Power: 22
Ruby has a few nice Perl-like tricks! On the other hand, Python was written to get away from the complexity of Perl.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

Reply With Quote
  #15  
Old March 16th, 2006, 04:00 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 30 m 28 sec
Reputation Power: 1025
Well I'm a perl lover, so that might be why i like ruby some

i think a hybrid of the two languages is called for. overall i prefer ruby, but there are some things that just look nicer in python

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Ruby Or Python


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT