Welcome to the Future of Smart Web Development

SmalltalkLogo-1

Today is the official launch of a campaign to promote the use of Smalltalk (and Amber) in the modern age of software development, especially as it relates to the Web. In our highly connected world, web technologies are absolutely central to the economic growth and social evolution of our society.

Why Smalltalk?

Smalltalk is a pioneer in programming language development. Constructed in the 1970s by those clever folks at Xerox PARC in California, Smalltalk was the first major OOP language, and still widely regarded as the best. Over the past four decades, it has been highly influential in the design of other important languages, such as Objective-C, Ruby, Groovy, Scala, and Dart. Today, Smalltalk is still used to write industrial and financial applications (rather like a secret weapon that confers a competitive advantage). It is alive and well, particularly in the Pharo incarnation, and it is emerging as a contender in client-side web development with the creation of Amber.

The beauty of Smalltalk lies in its simplicity and elegance, as well as its novel concept of a “live” development environment, where every object is active and you can examine it and change it at will. Ironically, this “novel” concept was created more than four decades ago! As a result, Smalltalk is eminently readable, almost like English, but it still manages to be succinct.

Smalltalk is prized for its development power and extraordinary productivity. The word “productive” is vastly overused and bandied about by nearly every new programming language that arrives on the scene today. However, Smalltalk has a long history to show definitively that a simple and expressive language, combined with an innovative approach to the IDE, can pay enormous dividends in academia and in the commercial enterprise.

Now with Amber, which compiles efficiently to JavaScript, we have brought the benefits of Smalltalk to the world of browser-based application development, the “final frontier,” as it were. Welcome to the future of Smart Web Development!

FAQ

Why is Smalltalk still relevant today? It may be viewed as a “modern” language in as much as it is closely tied to a novel approach to IDEs: the Smalltalk environment is a world of “live” objects that you can examine and change at will. The Smalltalk environment is not file-based; it is a system of live objects that can be stored, system state and all, into one location. Compare this to the traditional method of organizing source code using files and folders which is positively antediluvian!

“Source code in files. How quaint.”
Kent Beck

Moreover, Smalltalk adheres to modern language design principles that have become very popular. It’s a simple language with a highly readable syntax. Its language features are orthogonal with no unpleasant interactions. Not only is it designed to be easy to learn, it is also designed to be very practical and expressive in daily use.

Smalltalk can stand shoulder to shoulder with the likes of Dart, Swift, F#, and Scala, all recent entrants in the highly competitive field of programming languages.


Which Smalltalk should I use? Smalltalk is available in many different flavours and unfortunately this can be confusing to newcomers. In order to make things simple, I always recommend open source Pharo or Amber (which uses Pharo as the reference implementation). If you’re inclined toward a commercial Smalltalk, you have principally three choices: Cincom Smalltalk, VA Smalltalk, or GemStone/S.

Squeak is Pharo’s predecessor and still fairly popular. Redline Smalltalk is for those who want to run Smalltalk on the JVM. Essence# is for those who want to run Smalltalk on .NET. Dolphin Smalltalk is specifically for Windows. And there are still others. But, really, just keep it simple: stick with Pharo or Amber.


What resources are available for Smalltalk newcomers? To begin with, here is a most informative series of podcasts: http://smalltalkreflections.blogspot.ca/.

Here is an excellent Smalltalk tutorial video to get you started:

I actually went through the online interactive tutorial discussed in the video above. You get a better feel for the language by doing rather than watching.

This introduction to the Pharo programming environment (despite the title, it doesn’t really talk about the language itself) is very well done:

So is this introduction by Noel Rappin:

If you’re inclined to read, I recommend the book “Pharo by Example” (also available as a free PDF), which comes with a downloadable version of Pharo tailored for the book.

ab-12
Image

How learning Smalltalk can improve your skills as a programmer

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:

  • Image-based persistence
  • Objects: Everything is an object, and objects communicate only through messages (the “purest” OO, and one of the earliest)
  • “Live” programming
  • Advanced debugging techniques such as on-the-fly code changes
  • A simple, uncluttered IDE interface
  • Domain-specific languages (DSLs): The only way Smalltalk works, so programmers have to focus on the problem domain using a language and notation that is natural to that domain

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.

“Live” debugging dramatically shortens the edit-test-debug cycle.

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.


Originally published at techbeacon.com.