python stop worrying

general = { about, articles, links, projects }     meta = { date-posted: 2006-08-27 }

"Now look, boys, I ain't much of a hand at makin' speeches, but I got a pretty fair idea that something doggone important is goin' on back there."
-- Major T. J. "King" Kong, Dr. Strangelove

Over the past several months, I have bounced back and forth between the predominant use of Ruby or Python. I like both languages, and I have no problem with people using either one. It is a personal choice, as both languages are in my mind, equally powerful.

That being said, I have drifted more to the python side of the fence. This article outlines some of my reasons.

Easier to read other people's python code.

I have touched on this one before. I have found it easier to read the code other people write in python. I attributed this to the pythonic belief that while there are many ways to achieve task A, the set of ways can be reduced to a fewer number of 'good' or 'better' ways to do task A. In contrast, Ruby enforces fewer constraints on how tasks are achieved. This, to my personal experience, leads to a vast array of solutions to task A. I consider Ruby to be like Perl in this regard.

For me, the end result is that it takes me longer to grok discreet section of ruby code than it does a similar chunk of python code. Both equally powerful, both performing the same tasks. Maybe my mind just tends to think in more pythonic ways.

Clever code

In a similar vein to the above, I find that python code tends to be a bit less 'clever'. I have touched on this before as well. I don't like clever code. It is hard to quickly understand, hard to debug, and hard to maintain in the long run. This is more an expansion on the previous point.

If you program is small, and you are the only person having to deal with your own clever code, then you may never run into this issue. Consider, however, that a company has had someone working on an application for a while. That person leaves to a better job opportunity. The company hires a new developer to come in and work on the project, to add a few new features.

If there is a large amount of clever code, then it will take exponentially longer to come up to speed with what is happening, and to reach a point where the new developer can make changes to the codebase with confidence, and with fewer resulting bugs. I firmly believe that python makes this easier.

That isn't to say that writing convoluted clever code isn't possible in python. It just seems that people have to work much harder to do it. Python wants to be straightforward.

Performance

I find that python programs seem to run a bit faster, and use less memory, than Ruby programs. I have heard that argument that, "Hardware scales, while programmers do not. Programs can be developed in Ruby X times faster than in Language Y." I agree to a large extent. Programmers do not scale, much to the chagrin of management. The mythical man month showed this concept in fine detail years ago.

I do feel that performance of the underlying language should not be completely disregarded either. While programmers do not scale, and hardware does, consideration must also be given to the overall cost in the long term.

Note: This next example purely hypothetical. I have had the statement presented to me that Ruby is quicker to develop in than Python. I do not believe that is the case. However, I present it here for thought, insofar as performance of a language does matter to a certain degree.

Consider the following: Let us say that it takes a team of two programmers 9 months to develop a program in Ruby, and lets be overly generous and say that it takes a year to develop the same program in Python (which is likely a stretch, as I find programming in Python to be as easy as programming in Ruby, maybe easier). So, the above is claiming it takes 3 months longer to develop the app in Python. Let us also say that the programmers are paid 100K a year, each. That is 2 x 100K x .25 = 50K. So, according to the above, it would cost an extra 50K to develop it in Python.

Consider the phase where they ship the product to customers. If they sell it to 100 customers, and each customer has to buy a machine that is 10% more powerful to run the application, the economics does not scale on the other end of the equation. What if 1000 customers use it. What if it got wildly popular and 1 million people used it.

So, while programmers do not scale, the expense on the other end of the equation can largely outweigh the additional cost in time that might need to be spend using python. This isn't to say that there is any additional time that would need to be allocated to developing in python. I find python just as easy to use as Ruby, often easier.

For edification, here are a few links on performance benchmarks:

Libraries and third party libraries

One of the great strength of python is the community. The python community has a ton of useful libraries. Very good ones too. Ruby is a bit lacking in this regard. As time marches forward, I believe this will be less of an issue, as the libraries built around Ruby will improve. For now though, I have heard, and seen, a few instances where the lack of a Ruby library was a limiting factor.

Domain specific language?

Python has been around for quite a while. It is used in many many different places. This wide range of uses is great for testing the language, and hammering out issues in the various domains that it is being used in. It is not a stretch to say that Python is used to solve a diverse set of issues in many problem domains. This is likely due to the fact that python has such an extensive set of existing libraries, and also causes python to have an extensive set of libraries. A good chicken and egg problem. ;)

Ruby on the other hand, has seen explosive popularity recently with Ruby on Rails. It seems that most of the high profile talk about Ruby is focused on Rails. This is both good, and bad, for the language. If Ruby is pinned to Rails, or web frameworks in general, then it may gravitate towards being seen as a domain specific language. PHP is very much shoehorned into that role right now. I hardly ever hear about people using PHP on purely backend systems. While I am sure it is done, I wouldn't consider it 'popular'.

Ruby is a fine language, and I would love to see it continually grow. I hope that it doesn't come to be seen as a Domain Specific Language only.

Colleagues and Friends

I think another reason that I have gravitated towards Python has been the community. I have found them helpful and informative. In taking a look at some of the statements and attitudes of many python projects, I have generally liked what I have seen. Django and Trac are two fine examples.

On the other side of the fence, I have found a few high profile Ruby projects to be a bit...arrogant and combative towards differing viewpoints. While such sweeping generalizations towards an entire community, especially programming languages, should not be made based on the attitudes of a few high profile projects, I cannot help but have it influence my viewpoint. When someone touts BrandX as the best in the world, but does so while telling you that if you don't like it you are an idiot and should piss off, while someone telling you the merits of BrandY, in a thoughtful and reasonable way...well...people have made choices on less than that. ;)

Summary time. I think I chose to go with python because, well...because I like the language a bit more, and because I like some of what the language provides me with a bit more.

Do I like Ruby. Yes.
Do I think Ruby is a bad choice for anyone? No. Not at all.
Do I prefer Python to Ruby? Right now, yes I do.
Will that change in a year or two? I don't know. Perhaps.

"Gentlemen, you can't fight in here! This is the War Room."
-- President Merkin Muffley, Dr. Strangelove