lost password?

home
•  xaraya
•  rails +
•  django +
•  webdev
•  xamp
•  musings

rss
Tag this page
   

» Blogs that link here
last modified: Mar 22, 2007
(first posted: Mar 01, 2007)
(3882 Reads)
Permalink

Rails and Django - Programming Language (part 3/15)

A technical manager's guide to evaluating web development frameworks, with a detailed review of Ruby on Rails and the Django (Python) projects. (Start here: Whitepaper index)

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
RubyPython 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
irc.freenode.net (Feb 15, 2007)

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
My main beef with Ruby is that it's too much like Perl -- if you give the same task to five programmers, they come up with 5 different ways of doing it, and the other 4 can't read it at first. I started using Perl in 1996 and left it behind for Python a long time ago; Ruby is neat but it seems like a step backward somehow.

#

Rails and Django - Programming Language (part 3/15)

Posted by: jesus on March 01, 2007 11:06 AM
I just hate Ruby code. No fun there I can tell you. If you switch from python to ruby you are not annoyed with small things but with everything! Sucks I'm telling you. Python code is so nice and fluent and when you take look at the code you see what it does...

#

Rails and Django - Programming Language (part 3/15)

Posted by: mohammed on March 03, 2007 02:32 PM
Decent overview and kudos for being fair-handed. My only nit? You underrated the fun factor. A happy coder is a productive coder. Discovering ruby will make the most jaded perl/java/c#/etc... developer rediscover why they ever loved programming in the first place.

#

Re: Rails and Django - Programming Language (part 3/15)

Posted by: Anonymous on March 05, 2007 12:43 AM
Having moved from Perl to Python to Ruby (over several years), I can see your point. However, I view Ruby as "Perl done right". I find I'm blazingly productive in Perl, but code I've written 6 months ago is unintelligible, even to me, even when I've tried to make it as clear as possible, unless I refer back to my own documentation. With Python, I sacrifice a chunk of Perl's productivity, but get code that's much easier to understand (the "there's only one way to do it" philosopy at work helps a lot). With Ruby, and by extension Rails, I find I get the best of both worlds - the productivity of Perl, with the readability of Python. Don't get me wrong - on a scale of e.g. 10, I'd rate Ruby a 9 and Python an 8-8.5, but my productivity with Ruby would beat out my productivity with Python and that's a very big consideration.

#

Rails and Django - Programming Language (part 3/15)

Posted by: Tomas Jogin on March 06, 2007 06:12 PM
You are incorrect in claiming Ruby is not strongly typed. (You write that it indeed is strongly typed on one occasion, and then later turn around and write that it isn't.) Ruby is strongly and dynamically typed. Period.

#

Rails and Django - Programming Language (part 3/15)

Posted by: linoj on March 06, 2007 06:50 PM
Tomas, you're right, in the sense that you can do 1+2, and 'a'+'b', but not 'a'+2. Perhaps I'm confusing dynamically typed with not-strongly-typed, e.g. Ruby does not have typed method parameters or return values. In my defense :) according to wikipedia "these terms have been given such a wide variety of meanings over the short history of computing that it is often difficult to know what an individual writer means by using them." http://en.wikipedia.org/wiki/Strongly_typed

#

Rails and Django - Programming Language (part 3/15)

Posted by: Tomas Jogin on March 07, 2007 04:42 AM
I'm right in the sense that Ruby is strongly typed and there is no doubt about that. Strong typing is different from static typing. If you meant to say that Ruby is not statically typed (it's dynamically typed), just write that and leave strong typing out of it.

#

Rails and Django - Programming Language (part 3/15)

Posted by: Tomas Jogin on March 07, 2007 04:44 AM
You wrote that Ruby is not strongly typed because "data types share many of the same methods". This is completely and utterly unrelated to whether Ruby is strongly typed or not. Just because Ruby makes an effort to be consistent does not mean that the language is not strongly typed.

#

Rails and Django - Programming Language (part 3/15)

Posted by: linoj on March 11, 2007 10:52 AM
Thomas, thanks for the feedback. I have corrected the article to say both Ruby and Python are both strongly-typed and dynamically-typed.

#

Post a new comment

: This is not spam

Name :