Making decisions

It is interesting to have a look at how you make decisions in different programming languages. In Python, for example, the code is straightforward.

>>> if 1 < 2:
…     print ‘smaller’
… else:
…     print ‘bigger’
… 
smaller
>>> 

Maybe I’m wrong but I think that you don’t need programming experience to have an idea what is going on here. Let’s have a look at the same decision in Lisp.
CL-USER> (if (< 1 2) ‘smaller ‘bigger)
SMALLER
CL-USER> 
I’m not sure if everybody can immediately tell how it works. The code is very concise and clear. But it doesn’t help in this case. I don’t think the parentheses are the problem. Maybe it is because the ‘else’ is missing and you need the additional information about how else is handled here.
On the other hand, if the code is more descriptive, it can be a problem too. Let’s have a look at our decision in Squeak Smalltalk.
b := (1 < 2) ifTrue: [‘smaller’] ifFalse: [‘bigger’].
Transcript show: b; cr.
Maybe it is because of the message chaining that I need a bit more time to fully understand the code snippet. Or maybe I just did too much programming in C-style languages.
Advertisements
Making decisions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s