Back to the future: Smalltalk

I spent some time last weekend looking into Smalltalk again. The first time I did this was somewhere around 2004, when I played around with Ruby and discovered that it was strongly influenced by Smalltalk. Back then I watched an old video by Dan Ingalls on object-oriented programming which finally made me fully understand the essence of OOP: it’s all about messaging

[googlevideo:http://video.google.com/videoplay?docid=-2058469682761344178]

In my personal opinion, this video (or at least the message that Dan tries to communicate) should be better integrated in OOP courses at universities. Another invaluable resource for grasping these ideas is Design Principles Behind Smalltalk, again by Dan Ingalls. Of course, it’s difficult to understand what OOP is about if you have to learn it through a weak implementation. We learned the basics of OOP in C++ for example, which would be blasphemy to Alan Kay He once said Actually I made up the term object-oriented, and I can tell you I did not have C++ in mind. Here’s his definition of OOP:

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I’m not aware of them.

Before I looked into Smalltalk, to my understanding objects just contained a bunch of methods or functions that had access to the object’s context. I did not really grasp the idea that objects just respond to messages (or method calls in my definition). The real difference about this is that in Smalltalk messages are dynamically dispatched at runtime. A method is the function or subroutine that is invoked in response to the sending of a message, which will be matched to the message name (or selector) at runtime. In contrast, method calls in C++, Java and C# are statically bound at compile-time. There is thus a distinction between the semantics (or message) and implementation strategy (or method) in Smalltalk. Decoupling these allows for more flexibility, such as objects that cache all incoming messages until their database connection is fully set up, after which they replay these messages, or objects that forward messages to other objects (which might have even been passed in at runtime). This is of one of the aspects of extreme late binding in Alan Kay’s definition of OOP.

It’s exactly this run-time lookup of methods that enables effortless polymorphism. As explained in the video, at some point the intermediate factorial result will become an instance of LargeInteger, while in previous iterations it was an instance of SmallInteger. The multiplication message (*) is sent to this object, after which the correct method in the class LargeInteger is looked up for handling the message, allowing the existing code to continue to work. Java, C# and C++ have all inherited this feature (although C++ requires explicitly declaring methods as virtual for this to work, due to efficiency reasons). Smalltalk can even realize polymorphism without inheritance (also known as duck typing), although this is not shown in this video. Smalltalk has implicit interfaces: an object’s interface is the messages it responds to. If two objects both respond to a certain message, they are interchangeable (even at runtime). Traditional languages such as Java or C++ only support inheritance-based polymorphism (although something similar to duck typing can be achieved with C++ templates). Here’s the explanation by Dan Ingalls:

Polymorphism: A program should specify only the behavior of objects, not their representation.

A conventional statement of this principle is that a program should never declare that a given object is a SmallInteger or a LargeInteger, but only that it responds to integer protocol. Such generic description is crucial to models of the real world. Consider an automobile traffic simulation. Many procedures in such a system will refer to the various vehicles involved. Suppose one wished to add, say, a street sweeper. Substantial amounts of computation (in the form of recompiling) and possible errors would be involved in making this simple extension if the code depended on the objects it manipulates. The message interface establishes an ideal framework for such an extension. Provided that street sweepers support the same protocol as all other vehicles, no changes are needed to include them in the simulation:

More details on the differences between Smalltalk and current OOP languages are explained in Smalltalk: Getting The Message. I believe that understanding the original philosophy behind OOP helps you be a better object-oriented programmer in any language. Ramon Leon discusses the common mistake of magic objects which is an interesting read.

But let’s get to the point of why I started looking into Smalltalk again. At the moment, I mostly program in C# (and sometimes in Java), but I often feel frustrated with both languages. After being exposed to Ruby and Python, I feel like static typing requires me to write too much code and helps the compiler more than it helps me. Furthermore, Java seems to be overly engineered with all the factories, manager, readers and writers, while C# is often inconsistent or lacking in its implementation (e.g. anonymous methods are not really closures). Both languages are becoming increasingly complex with the addition of more and more features. Generics for example is just not necessary in a dynamically typed language. The problem with scripting languages such as Ruby and Python however, is that they are often interpreted and slow. I experimented a bit with JRuby (a Ruby implementation in Java with full access to Java’s class library) but that didn’t satisfy my needs either. After trying to code a simple Hello World Swing application in JRuby, I was stunned that it still required me to wrap code inside an ActionListener like Java does, while I really just wanted to pass in a Ruby block.

Update:: Nick Sieger pointed out that a newer version of JRuby does allow blocks to be passed in.

Other people have also been struggling with languages such as Java or C# (e.g. Jamie Zawinski, Mark Miller and Steve Yegge) or are looking for alternatives (e.g. Martin Fowler and Tim Bray). I think the popularity of Ruby might motivate more people to have a look at Smalltalk. Furthermore, if you know Ruby, it’s easier to get acquainted with Smalltalk. Besides lots of similarities in the class library (the Kernel class, the times message on numbers, etc.), Ruby already introduces the notion that everything is an object, objects in Ruby communicate through messages and Ruby has blocks. However, Ruby is not really equivalent to Smalltalk yet. Ruby introduced extra syntax to be more familiar to people that were used to C-style programming languages, thereby losing part of Smalltalk’s flexibility. In fact, the beauty of Smalltalk is that its entire syntax easily fits on a postcard. If you look closely at this example, even a conditional test in Smalltalk is implemented using messaging on objects. You just send the message ifFalse to an instance of the class Boolean, and pass in a code block you want to have executed when the value is false. It’s turtles all the way down.

Another problem I came across when developing in Java or C# (or in any other OOP language I used) was the difficulty of changing class hierarchies. Very often, due to time constraints, a design is just left in its original state, and the new requirements are supported by performing a quick hack. I suspect this problem is especially prevalent in so-called “research code” It gets even worse when programming in teams. Although this problem is generally known in software engineering and several strategies have been proposed to deal with it, I wondered why the promise of OOP failed here. Wasn’t OOP supposed to improve the situation and make spaghetti code obsolete?

Jeffrey Massung asked himself a similar question: What if the philosophy (OOP) wasn’t the problem, but the implementation (language) was?, and decided to write a 2D DirectX game in Smalltalk. It seems Smalltalk did indeed allow for easier design changes. Self (a language derived from Smalltalk) tries to alleviate the aforementioned problem by specializing through cloning of existing objects instead of through class hierarchies. It’s funny to note that the problem wasn’t that bad in Smalltalk, since you could still easily change the hierarchy, unlike in languages such as Java or C++.

The real power of Smalltalk is not its syntax, but the entire environment. I believe this is also key to understanding OOP. The current languages and tools (e.g. IDEs) we use for doing object-oriented programming are just weak implementations of the original Smalltalk environment. When working in Smalltalk, you are working in a world of running objects, there are no files or applications, everything is an object. For example, version control systems in Smalltalk are actually aware of the semantics of your code, they are not just text-based. When merging code they can show you what methods have been changed, added or removed, what classes were changed, allow you to decide which changes you want to keep, etc.. Although I think Bazaar is a great, it doesn’t come close to this way of working. Smalltalk allows live debugging and code changes, which is tremendeously useful. Ever wished that you could fix a problem while you’re debugging and immediately check if your solution works without having to recompile your application and start the entire process again? In Smalltalk (and Lisp) that’s possible. If you want to find out more about why Smalltalk is way ahead of current mainstream OOP languages, have a look at Ramon Leon’s Why Smalltalk.

Update:: Scott Lewis commented that I should have emphasized that Smalltalk is mostly written in Smalltalk: So when you subclass any object, you can go back up the chain of inherited objects and see how everything works. Likewise when you hit an error/bug, the debugger lets you delve about as deeply as you could possibly want into what is going wrong, and why it is an error. This is indeed a powerful aspect of Smalltalk, and an example of how it was influenced by Lisp.

Besides reading about Smalltalk, I have also been experimenting a bit with Squeak. Squeak is an open source implementation of the Smalltalk programming language and environment, created by its original designers. Squeak runs bit-identical on many platforms (including Windows CE/PocketPC). I will leave my Squeak experiments for another blog post though

To conclude, it seems that we are very good at ignoring the past. We just take our current systems for granted, and use them as a reference frame for future innovations. Marshall McLuhan once phrased it like this: We drive into the future using only our rearview mirror. I believe this is true in HCI research as well, as people like Dan Olsen have pointed out. He argued that our existing system models are barriers to the inclusion of many of the interactive techniques that have been developed. He gave the example of the recent surge in vision-based systems and multi-touch input devices, which get forced in a standard mouse point model because that is all that our systems support:

Multiple input points and multiple users are all discarded when compressing everything into the mouse/keyboard input model. Lots of good research into input techniques will never be deployed until better systems models are created to unify these techniques for application developers.

Research on toolkits is a lot less popular these days. We try to map everything into existing models, and always feel like we have to support legacy applications, which hampers significant progress. Bill Buxton has also studied innovation in HCI, and questioned the progress we made in the last 20 years.

I think the reason why so many great work was done by the early researchers in our field (e.g. Ivan Sutherland, Douglas Engelbart and Alan Kay) is — besides that they were very creative and intelligent people — that there was not that much previous work, they just had to start from scratch. Alan Kay once asked Ivan Sutherland how it was possible that he had invented computer graphics, done the first object oriented software system and the first real time constraint solver all by himself in one year, after which Sutherland responded I didn’t know it was hard.

16 Comments

Add yours

  1. I think you are on the right track with your analysis of the situation. If you read up/watch some of what Alan Kay has said about OOP you'll see that he considered it as just a starting point. In fact, he's said he's apologized for years that he coined the term, because it got everyone focused on objects, rather than the messages. OOP wasn't supposed to be the end all, and be all of programming. He expected that a younger generation of programmers (in the 1980s and thereafter) would come along and improve upon, but he says that didn't happen.

    I haven't looked at Erlang, but I've done a little research on it. It takes a similar “no centers” approach to development, and uses late binding, as Smalltalk does. It also uses message passing, but it's asynchronous. Instead of objects, it has things called “nodes”, I believe. Ericsson invented it, and has been using it for years to run its communication servers. From what I've heard they haven't had a server crash yet. Even if they run into an error, it's like Smalltalk. A developer can just fix the error on the spot, and the process continues.

    I think the reason we don't see more development using systems like this is not because they don't work, but because most programmers don't have the background to deal with them. Give Erlang to most developers and they'll give up on it in short order. They won't understand it. The same thing has happened with Smalltalk. People take one look at it and say, “Hey, why can't I use my code editor and my version control system with it? Why does it insist that I only use one language?”, and they give up on it. Quite a shame.

  2. Indeed, Smalltalk wasn't meant to be the endpoint. A Conversation with Alan Kay is a great summary of his viewpoint on this.

    Thanks for the insights on Erlang. I actually wonder how Croquet's TeaTime compares with Erlang's concurrency mechanisms (or E's for that matter).

    It is indeed a shame that people easily give up on different languages or systems. I can understand the practical issues though. You can rarely employ these languages in a day job, and it can be hard to cooperate with others who program in traditional languages. However, it all depends on what your goals are. I believe that in research one should be able to experiment and select the right tool for the job.

  3. It's so great to read something positive about Smalltalk. You've really done a great job of explaining why it works so well. I think the only thing I would emphasize additionally is that Smalltalk is mostly written in Smalltalk. So when you subclass any object, you can go back up the chain of inherited objects and see how everything works. Likewise when you hit an error/bug, the debugger lets you delve about as deeply as you could possibly want into what is going wrong, and why it is an error.

    One of the most subtle tests for objection-orientation for me is whether one uses “case” statements in code. In the most pure O-O they really are not needed, as you instead forward the message to the object in question, and it should “know” what to do.

    In the general C family, it would seem Objective-C comes closest to Smalltalk, and it's in wide use in the Mac's Xcode. You can get around static typing there by using the “id” type — which drives conventional C programmers up the wall, but there you go.

    Of course, there are a lot of times when the rigid object model of Smalltalk can be a little frustrating, and one begins to wonder if multiple inheritance might work better. In general, I don't think so, but there is an interesting approach to this suggested by the language Self, which is prototype-based. Self allows the manner of inheritance itself to be specified (in a sense) which creates one of those great complexity from simplicity situations — just like O-O itself.

    If you like Squeak, you should really also take a look at Dolphin Smalltalk. It hooks directly into Windows in a great way, and is a really well developed, mature environment. There is a free Community Edition, and the Professional edition (I think it's around $400 — been a while since I bought mine) allows you to compile executables.

  4. Dolphin Smalltalk was discontinued last year, unfortunately. I guess the Community Edition is still around.

  5. Help me understand something. I remember listening to a podcast with a guy (can't remember the name) talking about “aggressive learning” (I think). He said he gets into learning all sorts of languages, taking what he's learned and using it with the popular stuff. He used this same phrase you used when talking about the state of Smalltalk in the 1990s. He said developers used to say back then, “This is great, but I can't use it at my day job.” What does that mean exactly? He said this in conjunction with also saying something to the effect that Smalltalk was an “ivory tower” language, used in university study programs but not much else. There are some cases in point where this obviously doesn't apply. Smalltalk continues to be used at some major firms. Squeak is getting used in a few startups successfully.

    I can understand the obvious that it's not the same environment, computing model, or language that a company might already be using, but did it also mean that anyone who used it would effectively be isolated and unable to work in groups by virtue of the fact that everyone else didn't understand it, and refused to do so? Was it also cultural?

    In the case of Squeak it's able to interoperate with C. I've seen some Squeak libraries that use C-based DLLs. I haven't researched how it's done, but I know it works, and it seems to be something built into the language/VM.

    Maybe the problem in the 90s was that commercial Smalltalks (which I think were pretty much all that existed, with the exception of GNU Smalltalk) didn't interoperate with other stuff well, if at all. From my reading of Smalltalk's history, the fact that the most popular implementation was commercial was a big part of the problem.

    I remember a time when Smalltalk was actually popular. When I was in college, in the 1990-1992 timeframe, I used to see want ads for Smalltalk programmers on a fairly regular basis. The demand for it was not nearly as high as for C, but from what I remember it seemed like it was more popular than Ruby on Rails is today. By the time I graduated in 1993, though, the demand for Smalltalk had disappeared. I noticed this and wondered why it happened. I had been introduced to Smalltalk very briefly in my 4th year of college. I really enjoyed it. I was beginning to think that maybe I could find work using it, but those hopes were dashed pretty quickly.

    There are some first-hand account blog posts, and even some information pages around that tell the tale about what really happened to Smalltalk in the 1990s. It reads like a tragedy. It sounds like corporate mismanagement brought it down. When the corporate entities died, Smalltalk “went down with the ship”. It didn't totally disappear, but it might as well have. Cincom managed to salvage the leading commercial implementation, VisualWorks. They're selling it as ObjectStudio today.

    I think that Squeak offers Smalltalk a second chance at life, since it's not tied to any corporate entity. From what I've read GNU Smalltalk is kind of a weak implementation of the system. It's best used for scripting. Squeak is a full implementation of Smalltalk-80, and then some. Seaside has been breathing some life into Smalltalk. It hasn't taken off like RoR, but it's gotten some interest.

  6. The swing example you followed must be old. JRuby does allow you to pass a block as event listeners. See http://www.infoq.com/articles/jruby-deployment-… for example.

  7. Thanks for your kind words! I'll update the blog post with a few lines on Smalltalk being written in itself.

    From reading Jeffrey Massung's blog, Dolphin Smalltalk indeed seemed to offer easy integration of Windows libraries (e.g. DirectX). I am not sure how Squeak compares to this. They have an FFI interface and a .NET bridge as far as I know. An advantage of Squeak to me is that it runs on many platforms, including mobile devices.

  8. Thanks for pointing this out!

  9. The fact that you can rarely use Smalltalk in a day job has more to do with Smalltalk's (lack of) popularity than with its intrinsic qualities. As far as I know, there are only a handful of companies in Belgium that use Smalltalk, let alone offer Smalltalk jobs. The most well known is MediaGeniX. It seems they don't even require experience with Smalltalk anymore. In one of their job postings they say that applicants will be trained in the Smalltalk development environment. The European Smalltalk Users Group (ESUG) has an extensive list of companies that use Smalltalk.

    Lisp has the same problem. I found a list of Lisp companies, with only one from Belgium: PEPITe, a spin-off company of the University of Liège.

    So I didn't say that Smalltalk is not suitable for real-world software development, but it is just not used much in industry. As far as I know, most of the traditional programming jobs require either Java, .NET or C++. Furthermore, most programmers have no experience with Smalltalk. To the best of my knowledge, the only university in Belgium that actively teaches Smalltalk is the Vrije Universiteit Brussel, who perform research in programming languages. They host the Planet Smalltalk blog, hosted ESUG meetings and have employed some well-known people in the Smalltalk community (e.g. Roel Wuyts).

    I can imagine that managers are afraid that they won't find programmers to maintain their codebase if they use Smalltalk. Although Paul Graham once said: “if a company chooses to write its software in a comparatively esoteric language, they'll be able to hire better programmers, because they'll attract only those who cared enough to learn it”, I have a slight feeling that most companies don't think that way

    Of course, it all depends on the career you choose (and what you like to do). I can imagine that startup companies have more freedom to pick their preferred development tools.

  10. Thanks for your response. The “day job” thing was bugging me, because I wondered if other programmers were seeing something I wasn't. I haven't really had any work experience with it, so I wondered if in “the real world” there were difficulties with it that I haven't seen yet, and what those specifically were. I've heard from people who have used Smalltalk in work settings. Some have praised it. Some have said bad things about it. Ironically, I've found the people who didn't like it didn't understand what it was really about. It made me wonder how they got hired to do it in the first place. It felt like I was talking to someone who used C but didn't understand how pointers worked.

    I am familiar with the ESUG list of companies. Things like this give me hope.

    I consider myself lucky that I was exposed to Smalltalk in college. It was part of a senior course on programming languages, exploring how they worked; different types of systems (compiled, interpreted), different types of languages (imperative, functional, object-oriented). It was a long time ago, so I don't remember exactly, but I think we covered Smalltalk for 2 weeks. I also got exposed to Lisp, in a different class, covering it for the same length of time. So I got a “taste” of them. Honestly, I think there are more jobs for Lisp programmers now than there were back then. ITA Software uses it, as does Orbitz. Both are in the U.S., I think.

    As for what Paul Graham said, I'd like to believe that. The thing is, I think so many of the best developers don't believe they can find work using an esoteric language, so they learn Java or something, and apply their talents towards that. It's a self-fulfilling prophecy. A significant minority of talented developers are using and pushing for Ruby and Python to gain wider acceptance. That's good, IMO. They're a step in the right direction.

    I have a suspicion what Graham said is boosterism. He's very much into believing that everyone should do what he's done with his life. I tend to agree with what he says, but I think if he were right then we'd see more development in esoteric languages than we do today.

    I read up on what Graham wrote about his ViaWeb company. He began it using Lisp. He sold it to Yahoo. It's now called Yahoo Store. Yahoo eventually ported most of it to C++ and Perl. The reason they gave is they couldn't find enough Lisp developers to maintain it. Graham disagreed with that decision, of course, but that was Yahoo's determination.

    I think Yahoo didn't have enough faith in Graham's decision to use Lisp. They probably said to themselves, “Yeah, whatever. He's a bit eccentric.” If they understood his reasons, they would've pushed more for Lisp competence, pressuring CS programs to teach it more because, “We need Lisp developers.” That's my perception of how these sorts of decisions happen at universities. They try to deny that they respond to industry pressure, but they do.

    The thing is universities (in the U.S.) tend to teach them with a very clear message that “These are research languages. You won't be using them for your work.” One of the things that's bugged me for a while is how Lisp was pigeon-holed as an AI language right from the start, as if it wasn't good for anything else. This doesn't do it justice.

    Yes, startups have more freedom. So long as the founders can take care of most of the development themselves they can get away with that. I don't think corporate perception that there are too few developers who understand the esoteric languages is wrong. I think it would be a challenge to hire a whole lot of Lisp or Smalltalk developers. In my view it's a chicken and egg problem. You have on the one hand perception that there aren't enough developers who understand this stuff (so startups typically use PHP), and on the other you have a perception on the part of developers that they can't find work using them, so they go to PHP or Java.

    I think there is a perception as well that in order to be able to handle a project you MUST be able to hire X number of developers at a rate range Y. In addition, a lot of commercial concerns look at industry support. There's a perception that you need good 3rd party support for whatever development platform you use, and if it doesn't have it it's not worth using. What Graham says, and I believe it's true, is if you use an esoteric language you don't need as many developers. In fact large teams are inefficient anyway. Secondly, you don't necessarily need the third party support if you have a good technical team that can roll its own solutions. So it takes someone brave, willing to buck convention, to do this. They also have to believe that their technology is a competitive advantage. Unfortunately in the U.S. for the past several years there's been a growing belief that “I.T. doesn't matter” (ie. technology is not a differentiator), and that IT management is what can differentiate one company from the next. There's some truth to that, but it's not the whole story.

  11. I'm a little familiar with what you're talking about. From the screenshots I've seen, Dolphin integrated better with Windows in the visual sense. The browser window was just another window on the Windows desktop, for example, as was your app., and any debugger windows. ObjectStudio is the same way. Squeak has its own UI separate from the native UI.

    I tried my hand with the .Net Bridge, and it works well if you're just using the .Net framework class library (and of course any Smalltalk classes). Where it gets hairy is if you try to bring in an outside .Net library or do COM work through .Net. Then you have to use .Net's own late-binding mechanisms which are a pain. In Smalltalk you get late binding for free. With .Net you have to do gymnastics. It supports it, but it's no picnic. One of the projects I've had in the back of my head for a while is maybe I'll try my hand at improving the bridge for these scenarios. The experience should be better.

    Another option I heard about a couple years ago was WxWindows for Squeak. I've heard complaints about it, because it makes you do some gymnastics, but I think it works.

  12. Claudio Acciaresi

    October 22, 2008 — 20:22

    Really enjoyed the posts and the comments.

    I just wanted to add that here in Argentina there are at least eight companies working only with Smalltalk.

    We also have a conference that took place last year and this year is going to be back, here is the link: http://neuquina.lifia.info.unlp.edu.ar:8001/Sma

    Thanks a lot of writing this post was really cool to read and to know that there is a common sense of object oriented programming.

    Regards.

  13. Hi Claudio,

    Thanks for your kind words! I'm glad you enjoyed the post.

  14. Hi Claudio,

    Thanks for your kind words! I'm glad you enjoyed the post.

  15. This article I so true, keep on writing like this, enjoyment to read 290

Leave a Reply

Your email address will not be published. Required fields are marked *