
Smalltalk is usually perceived as an old, dying language - antiques from a bygone era. Nothing is farther from the truth.
Smalltalk is still very relevant. It is an excellent language for teaching programming to people without technical education. This is an excellent prototyping language for startups. It is a powerful industrial language
used by both large and small companies around the world . There are good reasons to consider using modern Smalltalk today, as much has been done lately to improve its capabilities.
You are not required to use Smalltalk in industrial programming, but try writing something on it and listen to your feelings. They should be familiar, because the implementation of the object-oriented paradigm in Smalltalk is so great that it affected a whole generation of OO languages, such as Objective-C, Python, Ruby, CLOS, PHP 5,
Perl 6 , Erlang, Groovy, Scala, Dart Swift and many others.
')
Studying Smalltalk, you will understand how all these useful functions in modern languages ​​have become a reality. Studying Smalltalk can also give you an edge among your peers, and it can also be a great tool for learning how to program.
What did Smalltalk give us?
Smalltalk’s contribution to the software industry is immense. Just take a look at this list of features and technologies that he introduced:
- Smalltalk introduced the world to a virtual machine (VM), which allows software to be platform independent. This is the same technology that Java (JVM) and .NET support, as well as Android (Dalvik).
- Smalltalk pioneered just-in-time compilation , a technique for dramatically improving the performance of bytecode software such as Java.
- The first modern development environment (IDE) appeared in Smalltalk, which included a text editor, a system and class browser, an object and property inspector, and a debugger. This has led to the emergence of many IDEs that developers today use, such as Visual Studio, Xcode, and IntelliJ IDEA. Personally, I think that none of these IDEs can compare with Smalltalk in simplicity, elegance and speed of development; the original is still the best!
- From the very beginning, Smalltalk had closures that are first-class functions that have lexical scope. In essence, a closure is a callback function that can see non-local variables in the place where they were defined. This can help you write much more compact and readable code. Closures are used in many languages, for example, in Java, C # and PHP.
- Smalltalk was the first language to support "live" programming and advanced debugging techniques, such as checking and modifying code at runtime . Today, real-time debugging is possible in C # using Visual Studio's Edit and Continue and Java functions using HotSwap.
- Smalltalk introduced the concept of MVC (Model-View-Controller) to the world. MVC is a software architectural template for implementing user interfaces. It is popular in desktop graphics and web applications. Nowadays, this is the very architecture that web developers are primarily studying.
- Smalltalk is largely responsible for test-based development (TDD) and extreme programming (XP), which are very important in current Agile practices.
- Smalltalk made “duck typing” a common expression (well, if it still paces your home). In duck typing, type checking is deferred until program execution — when reflection is used to ensure correct behavior. Today we find duck typing in many languages, including Java, Python, Common Lisp, Go, Groovy, Objective-C, and PHP.
- Smalltalk first introduced the use of object databases. Although they are not widely used, object databases have their own niche markets. The best example of an object database is GemStone / S , which is well suited for scalable, high-performance, multi-level distributed systems.
- Smalltalk introduced us to the first refactoring browser . Of course, refactoring support can be found in most modern IDEs.
- Smalltalk was instrumental in the development of the graphical user interface (GUI) and the “what you see is what you get” interface (WYSIWYG).
But how does learning Smalltalk make me a better developer?
Smalltalk has a number of functions that are well ahead of their time:
- Image-based preservation
- Objects: everything is an object, and objects exchange only messages (the “cleanest” implementation of OOP and one of the earliest ones)
- "Live" programming
- Advanced debugging methods such as changing code on the fly
- Simple, uncluttered IDE interface
- Domain-specific languages (DSL): the only way that Smalltalk works, so programmers need to focus on the problem using language and notation that is natural to this problem.
And there are a few more
features that make Smalltalk special.
Essentially, the key advantage of Smalltalk as a productive language and learning tool is that it removes most, if not all, of cognitive stress in industrial OO languages ​​such as Java. Smalltalk does not contain any syntax or confusing features. It politely gives you your way, so you can focus all your attention on the problem or application. The point is not that Java is a bad language, because it is more complex (and having 30-character class names); I'm saying that learning an unencumbered language with unnecessary OO functions can actually make you a
better Java programmer once you understand the concepts of OOP from another point of view.
Eliminating cognitive stress is the goal of many languages ​​— for example, Python, Ruby, Elixir, Elm, and Go. Even if you do not
feel it , stress is there. It is often said that programming in Smalltalk or Python is similar to Zen; your mind just flows easily and naturally along with the problem to be solved. This is the beauty and value of language simplicity, and Smalltalk has it to the full.
In Smalltalk, the concept of OOP is cleared up to 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 deep understanding of object-oriented programming and how to use it with maximum efficiency.
The simplicity of Smalltalk also makes it an ideal learning language for learning programming, especially if you do not have technical training. The simplicity of the language and tools allows you to focus your efforts on learning
programming techniques , rather than language constructs and formalism.
The live debugger significantly shortens the editing-testing-debugging cycle.How does Smalltalk work? Image-based programming approach
The main reason for the success of Smalltalk is an image-based software approach.
The image is a snapshot of memory that contains all the objects in your running application. It encapsulates the entire execution state of your program. The image can be saved to disk and later resumed exactly from the place where you left off!
The Smalltalk image may sound a bit unusual, but in fact it is very similar to something that is widely used today in IT: system images in OS virtualization, such as in VMware and VirtualBox. Keep in mind that Smalltalk was originally a standalone operating system created at Xerox PARC in the 1970s.
The Smalltalk image is similar to the DOM (Document Object Model) in a web application. Note that a web application is essentially an operating system, isolated in a web browser and devoid of direct access to the host file system and other resources. When the web browser is closed, the status 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 restrictions).
Even the spreadsheet is very close to the concept of the image. It encapsulates all the necessary information. It cannot access system resources. It can be saved and restored. And you should know that spreadsheets are still used to develop complex models and applications with their own language.
In general, the concept of the image is widespread. This is such a convenient way to develop software that a version of the image was created for JavaScript in the
Lively Kernel .
Everything in Smalltalk is an object
No exceptions: everything is an object. 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 purely syntactically.
For example, the following code fragment extends the
Number
class to support the 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: this is the
key message sent to the boolean object returned by the expression
(self <2) . The argument for the message is a code block (indicated by square brackets). In fact,
ifTrue: this is the first part of the message with two arguments, the second part is
ifFalse:.The unary message
new is sent to the
OrderedCollection
class to create a new collection. The message
printNl is sent to the result (being the object) of sending the message
my_factorial number 7. All this is very similar to natural language!
Reflection in Smalltalk
Reflection in Smalltalk is especially valuable as a mechanism for checking one’s own structure and runtime calculations. This is a very powerful mechanism that allows programs to expand themselves with new classes and methods or to ask the question “Who sent this message to me?”
Reflection is used to implement a powerful way to handle errors. When an object receives a message that it does not implement, the message
doesNotUnderstand: and the code of the original message are sent to it. There are many things that a program can do with the message
NotNUnderstand:, including extending its functionality!
The concept of image and reflection also allow Smalltalk to eliminate the boundary between the application and the IDE. Everything you need to develop, debug, and run the application is in the image. No need to ever leave the environment of your application. This is a completely holistic approach to software development that makes everything more Zen-like and productive.
Smalltalk Revival
The last 15 years of development in the Smalltalk world have made the language more attractive.
Smalltalk is now available for programming web interfaces using
Amber Smalltalk , which is translated into JavaScript. Amber runs exclusively in the browser. One of Amber’s amazing features is that when you import a JavaScript library, its objects can be processed in the same way as Smalltalk objects.
In 2002, the
Seaside web platform was released, which became the most popular web development tool in Smalltalk. The continuation approach (continuation) has provided the usual “call / return” mechanism for your web application. This allowed us to solve problems with a double query and the "Back" button. Very revolutionary for its time, and still not implemented in other web frameworks.
The
Pharo project began in 2008 to focus on modern software development techniques. He advanced Smalltalk much further than the previous open source project, Squeak, based on the Smalltalk-80 dialect. The Pharo project also launched a new type of IDE called the
Glamorous Toolkit . It is based on the idea that your programming environment needs to be "plastic" to fit your needs.
Last year, the beloved by many Dolphin Smalltalk became an open project, offering another great option for Smalltalk fans.
Dolphin Smalltalk is often praised for having one of the best IDE implementations.
Smalltalk Legacy: Program with pleasure
When you use modern software development tools such as JVM, Eclipse IDE, closures, live programming, MVC, TDD, VMware, and even a simple web application, remember their origin in Smalltalk and respect what you do. . Be grateful to him for the languages ​​you use, be it Objective-C, Python, Ruby, Groovy, Scala, Dart or Swift.
Working with the language from which all these great features and technologies have come is a unique opportunity to significantly improve your knowledge, mental acuity and performance as a software developer. The word “pleasure” is not always used in conversations about software engineering, but I think that Smalltalk and its OO brethren provide a lower cognitive barrier and ease of programming that can turn program development into fun.
about the author
Richard Eng is a retired software developer from Canada with over 30 years of experience in the IT industry. He has worked in video graphics, databases and finance, real-time software, iOS and Android mobile applications, and web development. He wrote mostly in C, but also used FORTRAN, Tandem TAL, C ++, C #, Objective-C, Java, Smalltalk, Python, and Go. He is currently leading the Smalltalk Renaissance campaign. Richard spends most of his time writing articles and essays.