Rails and Django - Programming Language (part 3/15)
Programming Language
It could be argued that the most telling difference between Rails and Django is the language they're implemented in, and the culture that has built up around the languages' communities.
Language Community
Here are some rough metrics on the popularity and communities of the the Ruby and Python languages (and Php for comparison).
| Programming Language | Ruby | Python | Php |
| Year invented | 1993 | 1991 | 1994 |
| TIOBE Index (Feb, 2007) | 10th (2.5%) (up from 20th Feb 2006) | 7th (3.6%) | 4th (8.8%) |
| User Groups, USA | 94 | 32 | |
Chat room members | 373 (#ruby-lang) | 357 (#python) | 330 (#php) |
| Freshmeat projects (www.freshmeat.net) | 327 | 2442 | 3798 |
| Frameworks (sampling) | Rails, Nitro, Merb | Django, TurboGears, Pylon | CakePhp, Symfony |
The TIOBE Programming Community Index (http://www.tiobe.com/tpci.htm), for what its worth, is a rough indicator of the popularity of major programming languages (the top 3 languages being Java, C and C++ respectively, FYI).
Both Php and Python have more history and a much wider breadth of usage than Ruby. Python, for example, is known to be used in mission critical projects at NASA, an indication of its quality and reliability.
The Ruby language, a relative newcomer in the West, was invented in Japan. In the US, most people know of (and use) Ruby in context of the Rails framework. Although many Ruby champions might strongly disagree with this statement.
Language Features
It is not my intent to directly compare the language structure, syntax and semantics. I will only share some impressions.
Ruby and Python are really quite similar. For example,
- Both are strong object-oriented languages. That is, everything is an object.
- Both are dynamic languages, lets you write code that writes code.
- Both are dynamically typed (because it doesn't use explicit data-type declarations) and strongly typed (because once it has a data-type it actually matters)
- Both have a compact syntax.
- Both are quite easy to read, which is important when going through other people's code (or even your own a few months later).
- Neither requires braces around bodies of code (Ruby uses “end” to indicate the end; although you can use braces if you want. Python relies on leading whitespace indentation).
- Both have an interactive command-line console.
- Both have testing infrastructures
- Both have doc generators (from comments in the source code)
- Both pride themselves on being a generation ahead of languages like C, Php, and Java
Ruby
Ruby has an especially compact syntax. No wasted words, that's for sure. It is said that Ruby's program statements read more like a natural language (or rather, a domain-specific language) than a general programming language. People pride themselves on how small they can reduce a block of code, like solving a puzzle. (And part of the challenge is to make the resulting code even more readable than the more verbose version; you certainly don't want to make it cryptic). This helps make programming in Ruby “fun”, a word people seem to associate with Ruby and Rails development. Common programming patterns (idioms) have become part of the Ruby culture.
Some cool things about Ruby: Don't need parenthesis on function calls. Dynamic blocks are like functions 'on the fly' , which can be used for example, with iterators and lists. (For example, ('a'..'e').each {|char| print char } evaluates to “abcde”).
RubyGems is the tool for downloading Ruby library packages.
Python
"Python code seems to be distinctive in having a particular character, and the Python community seems to have a lot less Cowboy Programmers than most other languages. If you hate to conform to standards, you won't like Python I guess." (http://mail.python.org/pipermail/europython/2005-April/004995.html)
Python has a strong following as a general purpose programming language. It is object-oriented, but you can use it procedurally if you want (Django doesn't). Python has a clearer (or perhaps just more formal) syntax than Ruby. Indentation (leading whitespace) is significant, to group statements.
Python programmers use the endearing term “Pythonic” to describe code that adheres to the Python philosophy. See http://en.wikipedia.org/wiki/Python_philosophy (it's also hidden within Python itself, enter: >>> import this at the Python prompt).
Python has a large selection of third-party libraries available and is used in a wide range of domains, including the engineering and scientific communities. Python has the setuptools package manager (amon others). There are over 10,000 libraries listed on the setuptools site.
Opinion
Ruby is a bit looser in how you express yourself, like its idiomatic expressions and dynamic blocks. In that, Ruby does seem more “fun”. Some people take to Ruby immediately.
Other people are really bothered by this aspect of Ruby, believing a programming language should be more concise, preferring that when there is one best way to express something, your code will be more clear, less prone to bugs, and more portable between programmers.
Ruby programmers who have used Python say they were grateful to leave behind little "annoyances", like parenthesis in function calls, having to declare the “self” argument to methods, and the special use of “__” (double-underscores) (e.g. __init__ for constructors). Python users defend these as non-issues that aid clarity. I suppose when little things like this bother you, it can grow increasingly annoying, until you finally want to kill someone, like in an Edger Allen Poe story (well, maybe that's an exaggeration).
You certainly don't want your language to be tedious. It doesn't look like either Ruby or Python are that. Far from it. But otherwise how important is this “fun” thing anyway? Seriously. (no pun intended). Ultimately the fun is in building websites that work, reliably. And I have no doubt, whichever language you use, the pain and frustration will still come when things don't work the way you expect (as I've witnessed on both framework's chat channels).
Conclusion: Both languages seem equally complete and flexible. Python is more mature and explicit. Ruby has that fun-factor. I rate them both a "4" (out of 5), for different reasons.




Rails and Django - Programming Language (part 3/15)
Posted by: vs. Perl on March 01, 2007 10:25 AM#