Tuesday, March 6, 2007

What Superhero Is Your Programming Language?

Stupid question, I know, but I'm beginning to very strongly suspect that Ruby is Spiderman. Why? Because with great power comes great responsibility.



There are all kinds of things you can do in Ruby which probably aren't a good idea. Do you want to override all numbers to return the string "puppy dog sandwich"? You can. It probably isn't a good idea, but you can if you want to. Want to override plus so it means minus? Go for it.

Rubyists who also love Lisp and Perl will of course point out that Ruby isn't the only language to give you this kind of power; it's just the only one you can also actually read. Pythonistas and Smalltalkers, however, will be quick to point out how easy it is to remove your own foot ballistically, and yet legibly, in their favorite languages too.

The flipside of all this, of course, is languages like Java, where the entire design is structured around preventing bad programmers from programming badly. I don't think it works. I think bad programmers, and good programmers who are still just learning for that matter, can mess up in Java just as badly as in other languages; it just takes longer to figure out, because there are so many extra words involved. In a way messing up is pretty crucial to learning, and using your powers irresponsibly is probably the only way to learn what responsibility even is.

Still, the next time you find yourself using #class_eval(), ask yourself, am I going to regret this when Uncle Ben is gone?

4 comments:

  1. When I get to specify the parser for the block I just passed to #class_eval, that's when I'll start seriously worrying about Uncle Ben.

    Yeah, yeah, I know, I can pass a string, and parse it how I like, but then I've got to either pepper the string with '#{...}' stuff or give up any hopes of closure semantics.

    ReplyDelete
  2. That actually sounds like the kind of thing where Lisp or Perl might get you further than Ruby. Although you could probably write a version of class_eval which allowed you to specify a parser for the block, couldn't you? As long as it eventually returned a block which could be passed to class_eval the usual way, I think this is reasonably possible. And probably a good way to solve FizzBuzz.

    ReplyDelete
  3. Interesting post, but I was really hoping you'd take it further. What superhero is Smalltalk? C is probably the Flash (fast, but not really good for anything else)... I would think of Lisp as Wolverine since it's community can be often grumpy but incredibly long-lived. Lua would definitely be Robin. Is Java the Thing?

    ReplyDelete
  4. I would say Perl is Reed Richards from the Fantastic Four, because it can bend and stretch in so many weird ways. Smalltalk is Superman! It can do anything, and nobody can tell that's an operating system when it puts on its "I'm a language" glasses.

    ReplyDelete

Note: Only a member of this blog may post a comment.