📜 ⬆️ ⬇️

How Studying Smalltalk Can Improve Your Programming Skills



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:


But how does learning Smalltalk make me a better developer?


Smalltalk has a number of functions that are well ahead of their time:


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.

Source: https://habr.com/ru/post/328156/


All Articles