Mike Austin's Blog

Friday, April 07, 2006

Syntax irregularities in Smalltalk

In one aspect, Smalltalk is a very small and elegant language. But I find there are some hidden intricacies when you actually use it. One example is the difference between using the messages whileTrue: and ifTrue:. whileTrue: expects a Block, while ifTrue: expects a Boolean. In the following, at first glance it's not understood why one uses square brackets and the other parenthesis:
[count < 10] whileTrue: [count := count + 1]
(count < 10) ifTrue: [count := count + 1]
Once you understand the semantics of Smalltalk then you comprehend it, but I find this somewhat odd. If Block supported the messages of Boolean, I think the syntax would be more orthogonal:
([x > 0] and: [x < 10]) and: ([y > 0] and: [y < 10])
Compared with the odd amalgamation of []s and ()s:
((x > 0) and: [x < 10]) and: [(y > 0) and: [y < 10]]

13 Comments:

Post a Comment

<< Home