Wednesday, October 24, 2007

Varieties in Code Design

One of the interesting things about writing software is the myriad of ways to express what it is that you would like the computer to do. When designing a class, function, or something else, you can make the syntax looks just about any way you like. The real interesting bit, is when multiple people need to work on a large project together. Everyone needs to be able to understand the code, so it's probably a good idea if you agree on code conventions beforehand. All of the below would do equally well, but which is most clear?

x = a + 5;
x = a.plus(5);
x = 5.plus(a); (You could do this in Ruby/)
x = plus(a, 5);
plus(a, 5, x);
a.plus(5, x);
set(x, plus(5, x)); (This looks a bit like Lisp.)

The list goes on and on.

Tune in next time for simple Python web-server fun.

2 comments:

amcclosky said...

the ability to treat "constants" as objects in ruby always freaks me out. it can occasionally be useful but its still just freaking weird.

Jeff Scudder said...

Very true. Also weird, but perhaps slightly less so, is the ease with which new methods can be injected into existing classes in Ruby and JavaScript (to name a few).