9 Replies - 5564 Views - Last Post: 07 December 2011 - 09:14 PM Rate Topic: -----

#1 muricula  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 24-November 11

Ruby vs Python

Post icon  Posted 06 December 2011 - 12:18 AM

I am a C# programmer interested in picking up a scripting language. I really don't know what I want to do in the future with a scripting language, but I'm curious and would like to try one out. You guys seems to be hard on people for asking specific questions, so I'll go overboard.
So, why did you choose ruby? Why not Python? How does Rails compare to Django? Is going from C# to one language to another easier? Is one better than the other for cryptography? Or math?
Are there any resources which you would recommend using? Do you recommend certain books or online tutorials? Should I download an IDE, or work out of a text editor (free is good)? What do I need to complete my ruby setup?
This is your opportunity to save another soul for your language.

Thanks for any answers to any of the above questions. I am looking forward to trying life without a compiler!

This post has been edited by Skaggles: 06 December 2011 - 03:47 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Ruby vs Python

#2 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 450
  • View blog
  • Posts: 849
  • Joined: 17-March 11

Re: Ruby vs Python

Posted 06 December 2011 - 07:43 AM

*
POPULAR

View Postmuricula, on 06 December 2011 - 12:18 AM, said:

So, why did you choose ruby? Why not Python?


Both are very readable, very flexible and dynamic languages, I would say the similarities far outweigh the differences.

But since we are making a comparison, in my eyes the main differences are.

The python developers believe there should be one-- and preferably only one --obvious way to do it. Mind this is not a strict rule, in programming there are always many ways to accomplish the same thing but in Python one way will stand out as the most typically python.

In Ruby this is most definitely not the case. Ruby developers believe that a method that is obvious to one person is not necessarily obvious to someone else, so they include many ways to do the same thing. This difference has far fetching consequences. The standard ruby libraries have far more functionality than the python libraries. This idea has also lead to ruby borrowing many concepts from many different programming languages and including them all.

OO is somewhat more deeply rooted in ruby. Everything is an object and methods in ruby are usually constructed in such a way that they return some transformation of itself. This makes methods very easy to chain. This has sort of created a "ruby way" of doing things. For example to get the maximum value of a list of numbers, in ruby one might write.

print gets.chomp.split(" ").map{|x| x.to_i}.max

gets, reads a line from input, so it returns for example "12 1 24 78 41 14\n"
chomp, removes a trailing newline, so returns "12 1 24 78 41 14"
split(" "), will split the string at the spaces, so returns ["12", "1", "24", "78", "41", "14"]
map{|x| x.to_i}, means transform every element of the list it is called on to it's integer, so returns [12, 1, 24, 78, 41, 14]
max, returns the maximum of the elements of an array so it returns 78

For more information, I'm sure there are a lot more detailed comparisons out there.

View Postmuricula, on 06 December 2011 - 12:18 AM, said:

How does Rails compare to Django?


I must say I have experience with neither, the last time I had my hands in web development plain php was the goto language.

View Postmuricula, on 06 December 2011 - 12:18 AM, said:

Is one better than the other for cryptography? Or math?


In theory no, both can express anything and can easily be interfaced with efficient Fortran/C/C++ implementations. Python however is much more established in the scientific community, so it is much more likely that the things you need already exist. When doing quick profiling of something mathematical, I usually use a specialized language Matlab mainly.

View Postmuricula, on 06 December 2011 - 12:18 AM, said:

Are there any resources which you would recommend using? Do you recommend certain books or online tutorials? Should I download an IDE, or work out of a text editor (free is good)?


You can try ruby in your browser http://tryruby.org/l...1/challenges/0. Also read http://www.ruby-lang...her-languages/. And while writing code, you'll probably want to keep the api documentation http://www.ruby-doc.org/core-1.9.3/ open in a webbrowser as a reference.

You already know C#, So you have some programming background, I find learning another especially a scripting language is not that much of a chore and offers valuable insights.

View Postmuricula, on 06 December 2011 - 12:18 AM, said:

What do I need to complete my ruby setup?


I use gedit under linux with an integrated console to run my code. But since you're coming from C# I'm going to assume windows use here, a quick google search turned up this http://rubyinstaller.org/.

This post has been edited by Karel-Lodewijk: 07 December 2011 - 10:06 AM

Was This Post Helpful? 8
  • +
  • -

#3 dawmail333  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 174
  • Joined: 02-July 07

Re: Ruby vs Python

Posted 07 December 2011 - 02:59 PM

Honestly though, I find Ruby's syntax to be a real pain: it seems to be TOO flexible, and I gave up writing something in it, and went back to Python.

You can easily install python from http://python.org/. I do recommend you install the 2.7 version at this stage: 3.2 is stable and everything, but not that many libraries have updated to use the new codebase, and the 2.x version is still being updated (include porting features backward from 3.x)

Python has a basic 'IDE' included in its package called 'IDLE'. It also includes a complete python reference in a Windows help file, which shows a significant portion of its examples around Monty Python sketches/movies. xD

IDLE does a basic REPL (Read, Evaluate, Print, Loop) by default, but supports writing whole scripts at a time.

However, when you want to write fuller programs, the best IDE tooling I found was not IDLE, not Netbeans or Eclipse, but surprisingly enough, Visual Studio 2010: http://pytools.codeplex.com/
Pytools is written by Microsoft's developer division, and provides the best intellisense and general support I've found. It also supports IronPython - the .Net implementation of Python, which could work quite nicely if you want to add scripting functionality to a C# program of yours.

(P.S. http://www.skulpt.org/ and http://www.trypython.org/ demonstrate Python and IronPython in your browser)

If you're after the shortest distance from familiar syntaxes, go for Python. If you're after something that can tie back into your projects at a later stage, also pick [Iron]Python.
Was This Post Helpful? 0
  • +
  • -

#4 UziTech  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 64
  • Joined: 26-October 10

Re: Ruby vs Python

Posted 07 December 2011 - 03:00 PM

I am not an expert in either language but a couple small comments.

Since I come from C# and PHP I am very annoyed by Python's lack of end statements. I'm sure if I would program in Python a lot I would get used to it but I have a hard time reading python code.

View PostKarel-Lodewijk, on 06 December 2011 - 08:43 AM, said:

The python developers believe there should be one-- and preferably only one --obvious way to do it.


I believe this is a plus for Python. When I started learning Ruby I got really confused by all the different methods that do the same thing. Especially when you are reading someone else's code and they use a method you are not used to.

In my opinion ruby isn't going very far. Python is already used by many big enterprises, including Google and facebook.
Was This Post Helpful? 0
  • +
  • -

#5 dawmail333  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 174
  • Joined: 02-July 07

Re: Ruby vs Python

Posted 07 December 2011 - 03:14 PM

View PostUziTech, on 08 December 2011 - 08:00 AM, said:

Since I come from C# and PHP I am very annoyed by Python's lack of end statements. I'm sure if I would program in Python a lot I would get used to it but I have a hard time reading python code.

The indentation was the hardest thing to get used to, but with a decent IDE, it's no trouble to read or write.

View PostUziTech, on 08 December 2011 - 08:00 AM, said:

In my opinion ruby isn't going very far. Python is already used by many big enterprises, including Google and facebook.

Ruby on Rails is definitely the most HYPED web development infrastructure. I wouldn't say it isn't going far.

View PostKarel-Lodewijk, on 06 December 2011 - 08:43 AM, said:

The python developers believe there should be one-- and preferably only one --obvious way to do it.

I'm a pragmatic coder. I will agree there are some ways that seem to work best, but in the long run, I see the 'best' method as the one that works.
Was This Post Helpful? 0
  • +
  • -

#6 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 450
  • View blog
  • Posts: 849
  • Joined: 17-March 11

Re: Ruby vs Python

Posted 07 December 2011 - 04:29 PM

View PostUziTech, on 07 December 2011 - 03:00 PM, said:

I am not an expert in either language but a couple small comments.

Since I come from C# and PHP I am very annoyed by Python's lack of end statements. I'm sure if I would program in Python a lot I would get used to it but I have a hard time reading python code.


Strange how opinions differ, I actually really like the fact that scopes depend on indentation. We indent our scopes in every other language to make it clear what belongs on the same level, so why shouldn't it have this meaning. If I were to design a language this would be one of the things I would definitely do.

View PostUziTech, on 07 December 2011 - 03:00 PM, said:

View PostKarel-Lodewijk, on 06 December 2011 - 08:43 AM, said:

The python developers believe there should be one-- and preferably only one --obvious way to do it.


I believe this is a plus for Python. When I started learning Ruby I got really confused by all the different methods that do the same thing. Especially when you are reading someone else's code and they use a method you are not used to.


This can be an issue. There is however structure in ruby code. Everything function that ends with a ? returns a boolean, functions that end with a ! manipulate the object they act on and other functions do not. That and meaningful class names with meaningful method names mostly make clear to me what is going on and what the possible side effects are without being familiar with the function used.

That and there are real gems among those methods you are not used to, they might be worth learning.

Quote

In my opinion ruby isn't going very far. Python is already used by many big enterprises, including Google and facebook.


This is just not true. Ruby on rails has real momentum, more so than Django or other alternatives. The available third party libraries are picking up. And ruby 1.9 performance is really on par with python. Google uses just about every language somewhere. And where you say facebook I say twitter, Scribd and Hulu.

The reason I like ruby is it allows me to say more with less effort. I have very little patience with syntactic salt. In ruby I can usually what I want to do, how I want to it. I also like to use some functional programming constructs and ruby supports those quite nicely.

This post has been edited by Karel-Lodewijk: 07 December 2011 - 04:44 PM

Was This Post Helpful? 0
  • +
  • -

#7 muricula  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 24-November 11

Re: Ruby vs Python

Posted 07 December 2011 - 04:51 PM

Thanks for all the thoughtful responses! I am pleased that this question has been featured.
However I have more questions.
So it sounds like ruby is the upstart new language, undocumented and currently used for a single purpose. However, it sounds like it is more intuitive to you, and as a result more confusing when you work with others. What is intuitive to one person may not be so to others. It is interesting to note that I have already found a decent basic ruby book, despite what others have stated.

Conversely python seems to have a way in which everything is done. No exceptions (no pun intended). There also seems to be this obnoxious idea that the runtime will throw an exception if your code is not formatted correctly.
Are they mutually inteligible? To some degree almost all software languages are. However, since I am good with C# I can write stuff in Java without too much pain, since the syntax is the same and the native methods are guessable. To what degree is this the case with ruby and python?
Also, there has not been much talk about IDEs. I see downloading these as a logical first step in learning a language, as it will push you back in line if your syntax is wrong, and you can browse methods easily. Is using an IDE ridiculous in a scripting language? Is there a preferred IDE for ruby(or python)?
If I decided to try ruby (or python) right now, and I wanted a beginners guide and a reference manual, what books would you recommend? In other words, what is sitting on your shelf right now?
Also, can someone explain what rails is simply in two sentences? I get what is basically is, but a simple definition would be nice.

Another thing. Contrary to your justified assumptions I am not running Windows at home (at work that is a different, story, but at work I am not doing any scripting). Is there an equivalent to IronRuby/IronPython which works with monodevelop?

So right now here is what I think: I agree more with Ruby philosophy, but it sounds like Python is used more. I can see them coexisting like Java, C#, and C++, they basically complete the same tasks in slightly different ways. Which to choose?
Was This Post Helpful? 0
  • +
  • -

#8 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 450
  • View blog
  • Posts: 849
  • Joined: 17-March 11

Re: Ruby vs Python

Posted 07 December 2011 - 05:58 PM

View Postmuricula, on 07 December 2011 - 04:51 PM, said:

So it sounds like ruby is the upstart new language, undocumented and currently used for a single purpose


Ruby is not undocumented, like I said before the api documentation is here http://www.ruby-doc.org/core-1.9.3/ is up to date and complete and there are sufficient resources out there. Ruby is quite new, but not as new as let us say C#.

View Postmuricula, on 07 December 2011 - 04:51 PM, said:

Conversely python seems to have a way in which everything is done. No exceptions (no pun intended). There also seems to be this obnoxious idea that the runtime will throw an exception if your code is not formatted correctly.


This will be just the same in ruby. It lies in the nature of dynamic languages. Both languages use dynamic typing and late binding. This means it is not known until runtime if a certain function or variable has the right type or even exist.

View Postmuricula, on 07 December 2011 - 04:51 PM, said:

Are they mutually inteligible? To some degree almost all software languages are. However, since I am good with C# I can write stuff in Java without too much pain, since the syntax is the same and the native methods are guessable. To what degree is this the case with ruby and python?


Like you say all software languages are. I would say python and ruby stand pretty close to each other. And I think both are at about equal distance from C#.

View Postmuricula, on 07 December 2011 - 04:51 PM, said:

So right now here is what I think: I agree more with Ruby philosophy, but it sounds like Python is used more. I can see them coexisting like Java, C#, and C++, they basically complete the same tasks in slightly different ways. Which to choose?


The agony of choice

This post has been edited by Karel-Lodewijk: 07 December 2011 - 06:01 PM

Was This Post Helpful? 0
  • +
  • -

#9 muricula  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 24-November 11

Re: Ruby vs Python

Posted 07 December 2011 - 09:07 PM

Quick apology for duplicating the topic. I am not used to the intricacies of forums. I thought that by posting in the ruby section, only the ruby people would read it. I wanted to hear the python side of the story by posting in the python forum.
In the future, if a topic spans two forums like this, where would you like me to put it?
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9501
  • View blog
  • Posts: 35,849
  • Joined: 12-June 08

Re: Ruby vs Python

Posted 07 December 2011 - 09:14 PM

@muricula - software development.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1