Hacker News new | ask | show | jobs
by spoiler 4772 days ago
I love Ruby's syntax. I tries Python, but I didn't like it as much as Ruby, what putt me off about python is the meaningful indentation (although I do not mind that in CoffeeScript). Also, Ruby itself is not slow, but CRuby (MRI, YARV, whatever you call it) is slow; Rubinius ("rbx") is a wonderful (and my personal favourite) alternative for MRI. In fact, I use rbx and EventMachine for a fun app that has a growing number of users! However, when I found some things were too slow in Ruby I just wrote a C extension (yes, yes, I know it's a bit of a controversy).

As to why I learnt it: it looked fun, and I was right, Ruby brings me pleasure!

2 comments

You should give Python another chance. Here's why:

> meaningful indentation

Indentation in other languages has meaning too. If you have Java code, for example, that looks like this:

   public static boolean isIncreasing(int a[])
   {
      boolean result = true;
      for(int i=1;i<a.length;i++)
         if (a[i-1] <= a[i])
            continue;
         else
            System.out.println("a is not monotonically increasing");
            result = false;
      return result;
   }
Can you spot the bug? The topic we're discussing is a huge hint as to what the bug is, but if the only clue you have is bad behavior in a longer program it can be much harder to spot. When skimming the code, the visual cue of the indentation is so strong that it's very easy for your brain to see what the programmer clearly intended to write rather than what's actually there. (The diagnosis of the above bug might be even hairier if the bug was introduced by inserting a "safe" print statement to help you debug an unrelated problem!)

Forcing your code's visual cues and behavior to match defeats an entire class of bugs. And even if you start out hating it, ultimately it's like the required semicolons in C/C++/Java: It's an annoyance at first, but after a while it becomes so automatic that you no longer stop to think about it.

Sorry, but the "bug" is that someone doesn't know well the language's syntax and/or has spent too much time with braceless languages and tries to put as less braces as possible because of their personal preferences, resulting in a wrong block structure.

Maybe I'm just different than you, but I immediately notice the missing braces. Actually, the visual cues I look for (even when skimming the code) are the braces, not the indentation; especially, the missing closing brace at the end of the block alerts me. The indentation is a plus, an added redundancy.

Moral of the story: not everyone reads code the same way.

Can you elaborate on what put you off Python's indentation?
Not the OP, but meaningful whitespace is an abomination unto the world.

It's difficult to elaborate on something that is a matter of taste, but some of us need our code blocks visually bookended.

When reading Python at anything over 3 levels of indentation I had to use a ruler to know what level I am currently in. Or similar, when there was multiple lines between two blocks or commands This was before I started using sublime text and I was very new to programming, also never tried Python in ST, to be fair! I mostly missed that visual cue where the block ends, I suppose.