| «« What's Up, Doc? | UI Candy »» |
|
About
I'm Ryan Lowe, a Software Engineering graduate living in Ottawa, Canada. I like agile software development and Ruby on Rails.
I write this blog in Canadian English and don't use a spell checker. Typos happen.
Projects
» Full-time Ruby on Rails freelancer
» Full-time with Rails since May 2005 » Former committer for RadRails (now Aptana) » I also have a few Rails side-projects in development: 1. wheretogoinTO.com Toronto nightlife 2. Hey Heads Up! TODO list and sharing 3. Layered Genealogy family history research 4. foos for foosball scoring 5. fanconcert for music fans (on hold) Hiring Rails developers? I can telecommute by the hour from Ottawa, Canada »» Email: rails AT ryanlowe DOT ca
BulletBlog
Now hosted on Hey! Heads Up -- check it out!
Syndication
Pings
Recent
Derek Lowe's (Ryan's older brother) words at Ryan's funeral
blog@ryanlowe.ca no more Forging Email Headers: Good, Bad or Ugly? Sarcastic Dictionary (Part 1 of Many) Tags Hierarchies Twisting Rails is Risky Business Risky Business? My Take on Early Alphas Whoa, it's August 2007 Closing Comments A Postscript to "Growth at the grassroots" »» All Blog Posts
Linkage
del.icio.us/ryanlowe
technorati/ryanlowe.ca/blog Aurora Roy Jim Andrew Trasker Travis Kibbee Karen Dr. Unk Ayana Van Bloggers Joel Spolsky Robert Scoble Tim Bray Dave Winer Raymond Chen James Robertson Ruby/Rails Bloggers rubyonrails.org weblog David Heinemeier Hansson Dave Thomas James Duncan Davidson Mike Clark Jamis Buck Signal vs. Noise Tobias Luetke Amy Hoy: (24)slash7 Jeremy Voorhis Eclipse Bloggers Planet Eclipse EclipseZone Luis de la Rosa Eclipse Foundation Kim Horne Billy Biggs Ian Skerrett Mike Milinkovich Bjorn Freeman-Benson Denis Roy
Archives
|
A Toe in Smalltalk Lake
On ambrai's web site I found a list of free Smalltalk books and I've been reading The Art and Science of Smalltalk. It starts off with no assumption of OO programming experience, and is old enough (1995) that it doesn't even mention Java, just C and C++. There are some interesting things about Smalltalk I've picked up from this book so far (please correct me if I go astray): Everything is an Object Everything in Smalltalk is an object. Unlike Java, there are no "primitive types" for performance. Variables Don't Have Type Variables, just as in Java, point to instances. Rather than saying that variables are "pointers", like in C or C++ most people say that a variable is a reference to an instance. Like Java, instances are passed to methods by reference. In Java and Smalltalk the "type" is the class that the instance comes from. The difference between Java and Smalltalk is that Java enforces types -- it makes sure that the type of the variable is the same as the type of the instance, or that the variable's type is a superclass or interface of that instance. Smalltalk does not enforce types and any variable may point to any type of instance. Messages Classes and instances still have methods, but you don't "call" them like C, C++ or Java. Instead you send the instance a message. If the instance has a method that understands the message, it's dealt with by that method. Otherwise the message is ignored. This ties in with the lack of variable types. Let's say instance A sends a message X to instance B. A might assume that B is of a certain type and will understand the message, but if B doesn't understand X it will be ignored. In Java, trying to call a method that didn't exist in an instance wouldn't even compile. At first glance, this seemed dangerous to me. But the book says it's part of the power of Smalltalk, so I'll wait to be convinced. I could see it being handy for refactoring, where in Java it's a lot harder to refactor from object 1 to object 2 because you have to correct all of the methods to even make it compile. That type-checking might save your ass, but it's also a pain because it's so restrictive. With good unit testing, this issue could go away. Encapsulation is Enforced There's no such thing as a public instance variable in Smalltalk. The only way you can get to an instance or class variable in Smalltalk is to expose it with a method. I can see this being a great thing, instead of allowing a possible free-for-all on public variables like in Java because a programmer didn't understand the concept of encapsulation. Blocks of Code You can store a block of code in a variable, send the reference around and execute it later. That seems a lot nicer than function pointers in C/C++ or the "handler" design pattern often used in Java. Small Language The language itself is quite small, it is the extensive class library that contains most of the functionality. This makes the language itself easier to understand. If you're curious about more differences, James Robertson recently pointed to a post from David Buck that goes through some advantages of Smalltalk over Java. Posted at June 03, 2004 at 04:54 PM ESTLast updated June 03, 2004 at 04:54 PM EST Comments
One small correction - you say above: "Classes and instances still have methods, but you don't "call" them like C, C++ or Java. Instead you send the instance a message. If the instance has a method that understands the message, it's dealt with by that method. Otherwise the message is ignored." As it happens, messages that get sent to an object that has no implementation of that method do not get ignored - an exception - MessageNotUnderstood - gets raised. That's handy, because: 1) When it's an inappropriate message, you find out (typically during testing) 2) In distributed systems, being able to handle this exception makes it trivial to implement proxies for remote objects » Posted by: James Robertson at June 4, 2004 04:44 PMGood to know, thanks James. :) » Posted by: Ryan at June 4, 2004 05:24 PMHere is a simple application to the message id... I have a whole bunch of unrelated objects that happen to have a 'Name'... it is nice that is Smalltalk, they will need not implement an IHasName interface. » Posted by: aforward at June 9, 2004 02:46 PM |