From: Stefan Lang Date: 2006-07-12T06:34:16+09:00 Subject: Re: Why Ruby over Python? On Tuesday 11 July 2006 17:00, jmdeschamps@gmail.com wrote: > Doug H wrote: > > howachen@gmail.com wrote: > > > Besides ROR, can you give me a reason why perfer ruby instead > > > of python? > > > > > > seems to many users, they are very similar in nature... > > > > > > such as > > > > > > 1. non C or Java style syntax > > > 2. focus on codes readability, not like Perl > > > 3. .. > > > > Go ask this same question over on comp.lang.python and you'll see > > why you might prefer ruby. > > Funny you ask: > http://groups.google.ca/group/comp.lang.python/tree/browse_frm/thre >ad/40d8d11e12cb00ba/12306d4d9b0ce50c?rnum=11&q=ruby+or+python&_done= >%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2F40d8d11e12cb00ba >%2F7256adbbc7f79afe%3Fq%3Druby+or+python%26rnum%3D1%26#doc_74bfb0743 >eff1367 Interesting. Someone there said that Python is more like Java and Ruby is more like Smalltalk. I've never written any Smalltalk, but I know some Lisp. IMO, Ruby and Python are both somewhere between Lisp and Java, Python closer to Java, Ruby closer to Lisp. I have learned many programming languages in the last two years and the ones I like most are Ruby, Lisp and Haskell. There is one thing these three languages have in common: It's easy and natural to construct domain specific languages in them, allowing you to write code that expresses more directly the problem at hand. Consider Rake/Rant syntax: task :a do ... end task :b => :a do ... end Or a well known (in the Haskell community) DSL in Haskell is Parsec; an example from the Haskell wiki: parseInput = do dirs <- many dirAndSize eof return dirs data Dir = Dir {dir_size::Integer, dir_name::String} deriving Show dirAndSize = do size <- many1 digit spaces dir_name <- anyChar `manyTill` newline return (Dir (read size) dir_name) Of course, Lisp is *the* language for DSL construction. Python, and more so Java do not allow you to construct a DSL. Thus in Python and Java, on the syntax level you are always limited to the few constructs the language provides: Defining classes and methods, constructing objects, calling methods, arithmetic expressions, branches via if/else, switch/case. This gets more limiting the bigger a project grows. Java people compensate this via huge frameworks that interpret XML files. Ruby's design is also more coherent than Python's. One example where Python really f****d up are properties. Python's properties are an ugly mess, just IMO. If you already know Java/C#/C++, you'll gain much more in learning Ruby than Python. -- Stefan