Home > Programming > Learning Python and Ruby – First Impressions

Learning Python and Ruby – First Impressions

To get first impressions, I’ll start with something really easy. A method that returns the age of a person, in seconds. Given age in years, the algorithm would look like age × 365.242199 days/year × 24 hours/day × 60 minutes/hour × 60 seconds/minute. The number of days per year was given by Google.


function ageInSeconds(age) {
    return age * 365.242199 * 24 * 60 * 60;


def ageInSeconds(age):
    return age * 365.242199 * 24 * 60 * 60


def ageInSeconds age
    age * 365.242199 * 24 * 60 * 60


So far, JavaScript is closest to C#, my current language of choice. The lines are clearly delimited with a “;” and the function scope is clear. The variables are weakly-typed, which means that they can change type during the execution of the code. This can be useful, but the source of many errors.

In Python, a “:” indicates the start of a scope. I think it weird that a language using carriage returns for line terminators could not use it here (I’m sure there is a reason, though). There is no scope termination, because the indentations define where the scope will end. To me, this is not only confusing, but illogical. The variables are strongly-typed, but are not declared.

In Ruby, the arguments are just put together like a phrase (which feels weird), there is no line terminator, and what the function returns is actually the last line encountered (this brings back some Crystal Reports nightmares). Like Python, Ruby variables are strongly-typed but are not declared. The scope end is specified by end, which reminds me of old Visual Basic times (not good).


This first post was more like an introduction to what I intend to do, and a comparison of the languages’ styles. The next posts will be centered around differences of feel, and differences in implementation.

Categories: Programming Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.