I want to learn a new language...

Levi Pearson levi at cold.org
Thu Feb 15 11:45:10 MST 2007

"Bryan Sant" <bryan.sant at gmail.com> writes:
> What's wrong with blocks being the last arg?  How would you prefer it
> (don't know how smalltalk does it)?

Well, Smalltalk allows a block in any argument place, giving them
first-class status.  This is due to the fact that Smalltalk has a very
simple syntactic and semantic model based on message-passing between
objects.  There are no syntactic control structures like loops,
conditionals, etc.  All of those things are constructed via classses,
messages, and blocks.  For example, let me describe how an if/then
statement is implemented:

(a > b) ifTrue: [ a ] ifFalse: [ b ]

The evaluation process first passes the > message to a with b as an
argument.  The object referred to by a then evaluates the primitive >
operation and returns either the canonical true or false object.  That
object then receives the ifTrue:ifFalse message with two blocks as
arguments.  Block contents are not evaluated when they are
constructed.  If the object receiving this message is the true object,
it will evaluate the ifTrue block.  If the object receiving this
message is the false object, it will evaluate the false object.  Thus,
we have been able to build conditional execution without having it
primitive in the language.

This would, of course, be horribly inefficient with a naive compiler,
but people have been working on making this fast since the late 70s,
and they have done a very good job of it.  A good Smalltalk
implementation should be in the same ballpark as Java depending on the
sort of application you're writing with it.  Strongtalk had just about
achieved that when the developers were aquired by Sun and put to work
on Java.  It also has an optional static typing system that you can
use to alleviate bugs that crop up due to type errors, though
interestingly enough that type system wasn't even used by the
mechanisms that made it so fast.

As a side note, Smalltalk syntax has some distinct advantages for
self-documenting code.  Messages have named arguments, so it is always
clear when you see a message send what the parameters mean.  Ruby
chose to do away with this in order to appeal to programmers coming
from languages syntactically similar to C, and I can understand that
motivation, but it makes me sad.  As far as I'm concerned, Smalltalk
is far superior to Ruby for systems and application work, while Ruby
has distinct advantages in the scripting and glue departments.


More information about the PLUG mailing list