I'm studying Smalltalk right now. It looks very similar to python (actually, the opposite, python is very similar to Smalltalk), so I was wondering, as a python enthusiast, if it's really worth for me to study it.
Apart from message passing, what are other notable conceptual differences between Smalltalk and python which could allow me to see new programming horizons ?
In Python, the "basic" constructs such as if/else
, short-circuiting boolean operators, and loops are part of the language itself. In Smalltalk, they are all just messages. In that sense, while both Python and Smalltalk agree that "everything is an object", Smalltalk goes further in that it also asserts that "everything is a message".
[EDIT] Some examples.
Conditional statement in Smalltalk:
((x > y) and: [x > z])
ifTrue: [ ... ]
ifFalse: [ ... ]
Note how and:
is just a message on Boolean
(itself produced as a result of passing message >
to x
), and the second argument of and:
is not a plain expression, but a block, enabling lazy (i.e. short-circuiting) evaluation. This produces another Boolean
object, which also supports the message ifTrue:ifFalse:
, taking two more blocks (i.e. lambdas) as arguments, and running one or the other depending on the value of the Boolean.
As someone new to smalltalk, the two things that really strike me are the image-based system, and that reflection is everywhere. These two simple facts appear to give rise to everything else cool in the system:
All of the above starts to come together in cool ways:
The image system and reflection has made all of these perfectly natural and normal things for a smalltalker for about thirty years.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With