Micro Focus is now part of OpenText. Learn more >

You are here

You are here

How learning Smalltalk can make you a better developer

Richard Eng Campaign Director, Smalltalk Renaissance

Smalltalk is widely perceived as an old, moribund language—an antique from a bygone era. Nothing could be further from the truth.

Smalltalk is still very relevant. It's an excellent instructional language for teaching programming to people who have no technical background. It's a superlative prototyping language for startups. It's an industrial-strength enterprise language used by businesses both big and small all around the globe. There are good reasons to consider using modern Smalltalk today, since much has changed in recent years to improve its prospects.

You don't have to use Smalltalk in production today, but try coding something in Smalltalk and see how it feels. It should feel familiar, because Smalltalk's implementation of the object-oriented (OO) paradigm is so excellent that it has influenced an entire generation of OO languages, such as Objective-C, Python, Ruby, CLOS, PHP 5, Perl 6, Erlang, Groovy, Scala, Dart, Swift, and so on.

By learning Smalltalk, you'll understand how all of those useful features in today's OO languages came to be. Learning Smalltalk could also give you a big edge in programming skills among your peers, and it could be a great tool for teaching programming to beginners.

What did Smalltalk give us?

Smalltalk has a rich legacy of contributions to the software industry. Just look at this list of features and technologies it introduced:

  • Smalltalk introduced the world to the language virtual machine (or VM), which allows software to be platform-independent. This is the same technology that underpins Java (JVM) and .NET, as well as Android (Dalvik). 
  • Smalltalk also pioneered JIT (just-in-time) compilation, a technique for dramatically improving the performance of bytecode software such as Java.
  • From Smalltalk came the first modern IDE (integrated development environment), which included a text editor, a system or class browser, an object or property inspector, and a debugger. This led to the many IDEs that developers favor today, such as Visual Studio, Xcode, and IntelliJ IDEA. Personally, I think that none of these IDEs can compare with Smalltalk's IDE in simplicity, elegance, and velocity of development; the original is still the best!
  • From the very beginning, Smalltalk had closures, which are lexically scoped first-class functions. In essence, a closure is a callback function that can see nonlocal variables in the location where they were defined. This can help you write much more compact and readable code. Closures are finding their way into many major languages, such as Java, C#, and PHP.
  • Smalltalk was the first language tool to support "live" programming and advanced debugging techniques such as on-the-fly inspection and code changes during execution. Today, live debugging is possible in C# with Visual Studio's "Edit and Continue" and in Java with HotSwap.
  • Smalltalk introduced MVC (Model-View-Controller) to the world. MVC is a software architectural pattern for implementing user interfaces. It's popular with desktop GUI applications and web applications. These days, it's the architecture that most web developers learn first.
  • To a large extent, Smalltalk is responsible for giving us test-driven development (or TDD) and extreme programming (or XP), which are both very influential in today's standard agile practices.
  • Smalltalk made "duck typing" a household word (well, if your house has a programmer in it). Duck typing is where "type checking" is deferred until runtime—when reflection capabilities are used to ensure correct behavior. We find duck typing in many languages today, including Java, Python, Common Lisp, Go, Groovy, Objective-C, and PHP.
  • Smalltalk pioneered the development of object databases. While they didn't make it into the mainstream, object databases have their niche markets. The best example of an object database product is GemStone/S, which is well suited to scalable, high-performance, multitier distributed systems.
  • Smalltalk gave us the first refactoring browser. Of course, refactoring support can be found in most IDEs today.
  • Smalltalk was instrumental in developing the graphical user interface (or GUI) and the "what you see is what you get" (WYSIWYG) user interface.

But how can learning Smalltalk make me a better developer?

Smalltalk has several killer features that were way ahead of their time:

And there are a few other features that make Smalltalk special too.

In essence, Smalltalk's key advantage as a productive language and learning tool is that it strips away most, if not all, of the cognitive stress in mainstream OO languages such as Java. Smalltalk presents no syntactical clutter or distracting features. It simply gets out of your way so that you can focus all your attention on the problem or application at hand. It's not that Java is a bad language for being more complex (and having 30-character class names); what I'm saying is that learning an unencumbered OO language can actually make you a better Java programmer once you understand its OO concepts from another perspective.

Eliminating cognitive stress is a fundamental goal of many languages—for example, Python, Ruby, Elixir, Elm, and Go. Even if you don't feel it, the stress is there. It is often said that programming in Smalltalk or Python is rather like Zen; your mind just flows effortlessly with the task. This is the beauty and value of language simplicity, and Smalltalk has this in spades.

In Smalltalk, OO is distilled to its most basic concepts of classes and methods, metaclasses and reflection, and most importantly message passing. Smalltalk, by virtue of its object purity and consistency, will give you a profoundly better understanding of object-oriented programming and how to use it to its best effect.

Smalltalk's simplicity also makes it an ideal instructional language for learning programming, especially if you don't have a technical background. The simplicity of the language and tools allows you to focus your energies on learning programming techniques, not on language formalities.

How does Smalltalk work? The image-based approach to programming

Smalltalk's principal claim to fame is its image-based approach to software creation. An image is a snapshot of memory that contains all the objects in your running application or system. It encapsulates the entire execution state of your program. An image can be saved to disk, and execution can later be resumed exactly from where you left off!

Smalltalk's image may sound a bit whacky, but in fact it bears a strong resemblance to something widely used in IT today: system images in OS virtualization such as we find in VMware and VirtualBox. You have to remember that Smalltalk was originally a stand-alone operating system when it was created at Xerox PARC in the 1970s.

Smalltalk's image also bears a strong resemblance to a web page's DOM (Document Object Model). Note that a web application is essentially a system unto itself, sequestered in the web browser and denied direct access to the host's file system and other resources. When a web browser closes, the state of the dynamic website can be saved or cached, and the next time the browser resumes, the website can be restored in the browser (with some limitations).

Even the lowly spreadsheet hews closely to the image concept. It encapsulates the entire execution state. It cannot access the host's system resources. It can be saved and restored. And you should know that spreadsheets are still used to develop sophisticated models and applications with its own language.

So the image concept is quite prevalent. It's such a nice way to develop software that a version of the image concept has been created for JavaScript in the Lively Kernel.

Everything in Smalltalk is an object

No exceptions: Everything is an object. There are no primitive data types. There are no control structures such as selection and iteration! Everything in Smalltalk is done by sending messages to objects. This is what makes Smalltalk so simple, elegant, and easy to learn. This is what makes the language so utterly clean syntactically.

For example, the following code snippet extends the Number class to support a non-recursive factorial operation:

  Number extend [
    my_factorial [
      (self < 2) ifTrue: [ ^1 ]
                 ifFalse: [ |c|
                   c := OrderedCollection new.
                   2 to: self do: [ :i | c add: i ].
                   ^ (c fold: [ :a :b | a * b ] ) ]]].

  7 factorial printNl.

  7 my_factorial printNl. "should be the same result as the previous line"

Here, ifTrue: is a keyword message sent to the Boolean object that results from evaluating the expression (self < 2). The argument to the keyword message is a code block (delineated by square brackets). Actually, ifTrue: is the first part of a two-part keyword message, the second part being ifFalse:.

The unary message new is sent to the OrderedCollection class to create a new collection. The printNl message is sent to the result (which is an object) of sending the my_factorial message to the number 7. The whole thing almost reads like natural language!

Computational reflection in Smalltalk

Reflection in Smalltalk is particularly valuable as a means for a program to inspect its own structure and computation at runtime. This confers enormous power, allowing programs to extend themselves with new classes and methods or ask "who sent this message to me?"

Computational reflection is used to implement a powerful way to handle errors. When an object is sent a message it doesn't implement, it receives a doesNotUnderstand: message, along with a reification of the original message. There are many things that the program can do with the doesNotUnderstand: message, including extending itself with new functionality!

The image concept and reflection also allow Smalltalk to eliminate the application/IDE boundary. Everything you need to develop, debug, and run your application is in the image. There's no need to ever leave your application environment. It's a completely holistic approach to software development that makes everything more Zen-like and productive.

Smalltalk's renaissance

The last 15 years of development in the world of Smalltalk have made the language much more appealing.

Smalltalk is now available for front-end web programming using Amber Smalltalk, which transpiles to JavaScript. Amber development takes place entirely in the browser. One of the amazing things about Amber is that when you import a JavaScript library, its objects can be treated just like Smalltalk objects.

In 2002, the Seaside web framework was released, becoming the most popular tool for web development in Smalltalk. Its continuation-based approach provided a conventional “call/return” mechanism for your web application. It can help resolve issues such as the double request and back button problems. Quite revolutionary for its time, and still not commonly adopted in other web frameworks.

The Pharo project began in 2008 to focus on modern software engineering and development techniques. It has brought Smalltalk much further along than the previous open-source project called Squeak, which was based on the venerable Smalltalk-80 dialect. The Pharo project has also spawned research into a new kind of IDE called the Glamorous Toolkit. It's based on the idea that your programming environment should be "moldable" to fit your needs.

Last year, the highly regarded Dolphin Smalltalk became open source, offering another wonderful option for fans of Smalltalk. Dolphin Smalltalk has frequently been praised for having one of the finest implementations of the Smalltalk IDE.

The Smalltalk legacy: Making programming fun

When you use the many facilities of modern software development such as the JVM, Eclipse IDE, closures, "live coding," MVC, TDD, VMware, and even the plain old web app, think back to their origins in Smalltalk and hold a greater respect for what you're doing. Have a greater appreciation for the languages that you use, whether they be Objective-C, Python, Ruby, Groovy, Scala, Dart, or Swift.

Working with the language that originated all of these great features and technologies provides a unique opportunity to greatly improve your knowledge, your mental acuity, and your productivity as a software developer. The word "fun" doesn't always enter into discussions about software engineering, but I think that Smalltalk—and its OO brethren—provide the low cognitive barrier and ease of programming that can make software engineering fun.

Keep learning

Read more articles about: App Dev & TestingApp Dev