What Java Owes to Smalltalk
I have been writing programs in Smalltalk at home for my own edification, while in my regular job I am mostly working in Java nowadays.
When I first started learning Java, I had no idea — no idea — just how much Java owed to Smalltalk! I still didn’t really appreciate it until recently, when I started digging into Smalltalk more seriously. From the notion of everything descending from “Object” to garbage collection to the inheritance model to polymorphism, almost everything Java does is basically aping Smalltalk. Often not very well. I am using Java’s Collections a lot, and even though Collections are a relatively new transplant from Smalltalk, compare this:
for (Iterator iter = myList.iterator(); iter.hasNext(); ) {
myThing thing = (myThing) iter.next();
thing.doSomething();
}
with this:
myList do: [:thing | thing doSomething ]
I’m not just griping about syntax here; which one, conceptually, looks and feels more elegant, more intuitive? Look at all the method calls and casts you have to do just to iterate through a list of arbitrary objects in Java.
That’s the sort of thing I didn’t really notice until I started working with Smalltalk. Now I shake my head and wonder how much better life would be if it had been Smalltalk rather than Sun’s Java that had been poised to catch the wave in the 90s.
Now, some Smalltalk constructs still feel more awkward to me than the Java equivalents. For example:
if (boolValue) {
doThis();
} else {
doThat();
}
feels more intuitive to me than:
boolValue
ifTrue: [ doThis ]
ifFalse: [ doThat ]
But I realize this is a matter of taste, and being more comfortable with familiar syntax.
Frankly, I like Perl’s flexibility even better in this regard:
doThis() if $boolVal;
or
$boolVal or doThat();
Actually, this is all a good argument for programmers to be multi-lingual. I don’t think anyone can be a “master” of any language until they are fluent in many.
Here is a good article on the advantages of dynamic typing. I am becoming convinced that the “advantage” of static typing is that it provides minor babysitting services for bad programmers. Try writing a Java package that performs all sorts of calculations with int, double, float, and long data types and has to go back and forth between them…. the need to cast, convert, and develop special ways of handling “loss of precision” will drive you nuts.
August 13th, 2004 at 12:54 am
If you keep in mind that everything in smalltalk is “Receiver Message [: argument]” then something like “(someBoolean) ifTrue: [someblock].” is rather elegant and not hard to understand.
BTW - Apache has collection library enhancements that mimic Smalltalk’s.
August 13th, 2004 at 1:00 am
If you find yourself missing the Perl thing too much, you could implement #if: and #unless: for the BlockContext class.
August 13th, 2004 at 1:04 am
Historically speaking, I think most of the Smalltalk in Java came by way of Objective C. But your point remains. -Peter
August 13th, 2004 at 4:21 am
Hi - you should notice that controls structures in Smalltalk are implemented as methods. Therefore if
you need something like your perl example “doThis() if $boolVal;” in Smalltalk you just have to add
a new method #if: to the class BlockContext/BlockClosure (depending on the dialect you use this is the
class for a block) so you can write:
[doThis] if: aBoolean
The implementation of this method is easy:
if: aBoolean
aBoolean ifTrue: [self value]
All this is possible because blocks are objects like anything other in smalltalk,
so you can construct them dynamically, pass them as arguments, …
This is one of the points that make Smalltalk so rich - think of a “repeat-until”
construct: you have it in Pascal, but not in C++, Java and Smalltalk. The difference
is that it is easy to add in Smalltalk without changing the Parser or asking
the compiler vendor. Be warned: This makes Smalltalk a drug - if you’ve started to
understand it’s ideas you will never like to return to other languages.
August 13th, 2004 at 10:41 am
You can do ‘boolVal or: [ doThat ]’ in Smalltalk. For the other one you’d need to extend BlockClosure. If you add something like
BlockClosure>>if: aBoolean
^aBoolean ifTrue: [ self value ]
Then you can do
[ doThat ] if: boolVal
The beauty of it is that there aren’t any hardwired, keyword based, control structures. It’s all regular messages, so you can add your own at will. The only concern is how readable your extended control structures will be for others.
August 13th, 2004 at 1:05 pm
1. Learn from Smalltalk.
2. Learn from other languages: Nice, Scala, OCaml, Python, Lua, Clean, …
Read code http://shootout.alioth.debian.org/langs.php
August 13th, 2004 at 1:10 pm
Smalltalk and Objective-C, which is a combination of C and Smalltalk.
Here’s a link to an old Usenet post by Patrick Naughton who worked on Java
with Gosling in the early days when Java was called ‘Oak’. A bunch of
Objective-C-oriented people from NeXT joined the Oak group in 92/93.
According to this, Gosling was familiar with Smalltalk, while Naughton was
familiar with (and impressed by) Objective-C.
http://www.virtualschool.edu/objectivec/influenceOnJava.html
December 8th, 2011 at 11:29 am
< cite >< strong >< a title = “http://grew.bombmp3.ru/?p=6527″ href = “http://grew.bombmp3.ru/?p=6527″>:|< / a >< / strong >< / cite >…
sps
…
December 8th, 2011 at 12:47 pm
< strike >< strong >< a title = “http://except.filmtape.ru/?p=580″ href = “http://except.filmtape.ru/?p=580″>:x< / a >< / strong >< / strike >…
спс за инфу
…
December 9th, 2011 at 4:42 am
< em >< b >< a title = “http://let.animalsfun.ru/?p=1383″ href = “http://let.animalsfun.ru/?p=1383″>
< / a >< / b >< / em >…
спс
…
December 9th, 2011 at 11:31 am
< blockquote cite= “possible” >< strong >< a title = “http://notice.hraniteli-chita.ru/?p=6118″ href = “http://notice.hraniteli-chita.ru/?p=6118″>
< / a >< / strong >< / blockquote >…
спасибо за инфу
…
December 10th, 2011 at 4:17 am
< abbr title = “produce” >< b >< a title = “http://hat.stroitelstvo.asia/?p=6179″ href = “http://hat.stroitelstvo.asia/?p=6179″>:o< / a >< / b >< / abbr >…
спс за инфу
…