Test-Driven Development

Summarized using AI

But Really, You Should Learn Smalltalk

Noel Rappin • March 17, 2014 • Earth

The video titled "But Really, You Should Learn Smalltalk," presented by Noel Rappin at the MountainWest RubyConf 2014, explores the Smalltalk programming language and its unique features. Rappin discusses the mystique surrounding Smalltalk, its historical significance, and how learning it can transform a programmer's understanding of object-oriented programming.

Key points covered in the presentation include:
- Introduction to Smalltalk: Rappin introduces Pharaoh Smalltalk, a live programming environment where users can write and execute Smalltalk code dynamically.
- Unique Features: Smalltalk uses 1-based arrays, meaning the first element is accessed at index one, contrasting with the more common zero-based indexing.
- Object Orientation: The language is regarded as the purest form of object-oriented programming, focusing heavily on objects and message-passing.
- Interactivity: The dynamic environment allows for real-time interaction with the code, enabling developers to test and tweak their programs instantly.
- Programming Constructs: Rappin outlines important aspects of Smalltalk, such as variable naming conventions, message passing, and the way conditional statements and loops are handled.
- Test-Driven Development Example: A practical demonstration involves creating a fraud detection system by developing test cases, illustrating the seamless integration of testing within the Smalltalk environment.
- Impact on Programming Perspective: Rappin emphasizes that learning Smalltalk can change the way programmers think about coding, encouraging a deeper understanding of the principles that govern programming languages.
- Challenges of Adoption: Despite its advantages, Smalltalk's popularity has diminished compared to languages that adapted to changing demands, which can lead programmers to overlook its unique strengths.

In conclusion, Rappin argues that understanding Smalltalk not only broadens a programmer's toolkit but also provides insights into best practices that are applicable in other languages, particularly Ruby. He encourages attendees to appreciate Smalltalk’s capabilities and consider its relevancy in modern programming discussions, particularly regarding the MagLev project.

But Really, You Should Learn Smalltalk
Noel Rappin • March 17, 2014 • Earth

By Noel Rappin

Smalltalk has mystique. We talk about it more than we use it.
It seems like it should be so similar to Ruby. It has similar Object-Oriented structures, it even has blocks.
But everything is so slightly different, from the programming environment, to the 1-based arrays, to the simple syntax. Using Smalltalk will make you look at familiar constructs with new eyes.
We'll show you how to get started on Smalltalk, and walk through some sample code. Live coding may be involved.
You'll never look at objects the same way again.

Help us caption & translate this video!

http://amara.org/v/FG2V/

MountainWest RubyConf 2014

00:00:24.650 Welcome to Mountain West Smalltalk chapter. I'm glad to see you all. This is going to be fun, I hope. I promised Ryan that if things went poorly, I would start singing 'Layla.' It's a long story, but hopefully nothing will go wrong.
00:00:28.500 This is Pharaoh Smalltalk. You can get it by going to pharo-project.org. This is essentially a stock startup image. I haven't made many changes except for deleting the startup tutorial screen and fiddling with the fonts.
00:00:36.210 Smalltalk has the concept of a workspace, which is something similar to an REPL (Read-Eval-Print Loop) that we’re all familiar with from Ruby. By the way, off the top of your head, how many people here have actually played with Smalltalk at some point? How many haven’t? I want you to not pay any attention to me at all. Alright, say hi on Twitter for me. Enjoy your codebase.
00:01:11.250 In the workspace, this is live. I'm in a live environment, and I can type Smalltalk code. For example, typing '2 + 2' and hitting return doesn’t produce visible output yet because hitting return doesn’t mean anything here. In Smalltalk, you can think of it as not being a line-by-line REPL. Instead, it waits for me to tell it that I'm done writing.
00:01:34.950 There are keyboard shortcuts, but basically, I have a menu here with several options that I can use for executing code. One of the things that looks promising is ‘Do It.’ Although it appears that nothing happens, in the background, it has processed '2 + 2.' It added the numbers, but it didn’t display the output because I didn’t ask it to do anything with that value.
00:02:03.930 What I actually want to do at this point is print the result. Now the Smalltalk workspace does what I have asked: it responds with '4' as a result, conveniently highlighted so I can keep typing. I can delete the whole response if I want. This acts as a live scratch pad for the Smalltalk environment. I can have multiple workspaces open and run anything in the Smalltalk environment.
00:02:57.170 For instance, I have a bunch of snippets in Text Expander and can run anything in Smalltalk. This is a core part of the Smalltalk library. I can execute multiple lines of code at once. For those who haven’t used Smalltalk before, what do you think will happen when I execute these two lines? The first line creates an array, and the second accesses index one of the array. Don’t say it out loud; write it down on paper or whisper it to your neighbor.
00:03:31.050 You might be surprised to learn that the answer will be 'nil' because Smalltalk arrays are 1-based. This means that the first element of the array is actually at index one, not index zero. That might sound strange considering how we’ve been conditioned by years of working with zero-based arrays.
00:03:49.500 In fact, normal people count such that the first item in an array is actually the first item. Just to clarify, my patch to fix Ruby's array-indexing issue was famously rejected.
00:04:02.190 Now, looking at this top line, I have 'x' which is a local variable, ':=', which is the assignment operator, and I'm creating a literal array. I can inspect this in Smalltalk using a special Smalltalk window called an Inspector. This window provides a live view of the object in question, showing the actual object as it is.
00:04:50.460 I can go through and see all of the elements of that array. It shows a live workspace window, allowing me to inspect the state of the object. For example, I can check the value at index one and print it, interacting live within the Smalltalk environment.
00:05:16.950 I’m Noel Rappin, I work at Table X, a Smalltalk consulting company in Chicago. I’m going to spend the next, oh I don't know how long, talking about Smalltalk. Really, you should learn Smalltalk.
00:05:45.930 Randy alluded to this this morning. I will talk a little about why it's beneficial, how to learn it, and what it looks like. I have three reasons why Smalltalk is interesting.
00:06:02.910 In the Ruby community, Smalltalk has a sort of legendary mystique status. It's like the dinosaurs of programming languages; we know it was used for really cool things, but it's less commonly employed today.
00:06:16.200 No one quite knows why it went extinct, but it seems really cool and has that mystique surrounding it. I want to demystify it a little here.
00:06:30.300 Smalltalk is considered the purest Object-Oriented language. Earlier today, we learned about Scheme, the purest functional language, and Ruby is quite distant from being a pure language. Smalltalk's syntax is minimal, and almost everything exists in its object library.
00:06:51.240 The reason to work in a pure language is that it forces you to confront and understand the single idea that the language is built around. In Smalltalk, to be successful, you must understand objects and message-passing, as those are the only constructs in the language.
00:07:19.680 Smalltalk operates within a live dynamic environment. I have mentioned it like four times already and will probably say it another thirty-seven times. This dynamic environment is quite different from the environments we are used to.
00:07:39.030 In our usual programming experience, we have files that are interpreted and manipulated. In Smalltalk, the environment is a live binary state of every object in the system. The implications of this approach are significant.
00:08:08.070 On the positive side, you have access to system state in a way that you can only dream of in Ruby, and conversely, the downside is the ability to access system state can lead to rewriting fundamental objects unexpectedly.
00:08:41.250 Much like Lisp, Smalltalk is regarded as an evolutionary road not taken. Many programmers in this room have likely spent their careers working in languages heavily influenced by C.
00:09:05.520 As a result, some things you believe are immutable about programming languages may not be true in Smalltalk. The naming conventions and the flow of the language influence how you think about programming.
00:09:23.250 Being fluent in Smalltalk will expand your toolkit, enhancing the range of solutions you can apply to problems. There's a Perl quote stating that only programming languages worth learning are the ones that change how you think about programming.
00:09:33.660 Smalltalk is likely to change the way you think about programming. Additionally, studying Smalltalk provides access to Smalltalk best practice patterns, which is renowned for its contributions to dynamic programming languages.
00:09:56.390 Not everything in ‘Best Practice Patterns’ is specific to Smalltalk, as about 85% applies to Ruby. However, there is a noticeable lack of books that delve into pragmatic programming, discussing details relevant to your day-to-day coding.
00:10:23.300 It's important to note that my first published technical writing was an introduction to Squeak, which is similar to what I'm discussing now, albeit it was thirteen years ago.
00:10:39.940 I cannot teach you all of Smalltalk in thirty minutes, but I can cover about seventy-five percent of it in a minute and a half, so hold on tight.
00:10:56.270 Local variables in Smalltalk start with a lowercase letter, while global variables, including class names and global constants, start with an uppercase letter.
00:11:01.600 Smalltalk has a small set of reserved words: self, super, nil, true, and false, which function very similarly to their counterparts in Ruby, but are implemented a bit differently.
00:11:37.210 Character literals in Smalltalk are defined by dollar signs, whereas strings are delimited by single quotes. Comments are instead marked using double quotes, which often confuses newcomers to the language.
00:12:03.430 Smalltalk also has symbols denoted by hashtags. Additionally, it features two array literal syntaxes: one evaluated at compile time and the other at runtime using braces.
00:12:29.040 Smalltalk uses ':=' for assignment and has a block syntax that closely resembles Ruby’s. However, with multiple variables, they are space delimited rather than comma delimited, and the caret indicates the return value.
00:13:00.740 There are three types of messages in Smalltalk: unary messages, binary messages, and keyword arguments. Each message must have an explicit receiver, ensuring clarity in communication.
00:13:48.550 Unary messages are straightforward, while binary messages have a limited set of symbols placed between two objects, making the second object an argument, similar to Ruby. Keyword arguments allow for greater flexibility.
00:14:07.560 In Smalltalk, a very strict left-to-right flow of control persists, and there is no concept of operator precedence, which may differ from what you're used to in other programming languages.
00:14:35.080 For instance, evaluating '2 + 3 * 5' results in '25' since two plus three is evaluated first and multiplied subsequently. Parentheses can be used to specify order, which would yield a result of '5'.
00:15:01.520 It is important to note that key constructs, such as class creation and loops, aren't part of the core language but rather belong to the library. Conditional statements, for example, are handled through Smalltalk's block syntax.
00:15:20.920 Blocks in Smalltalk are first-class objects, allowing them to be passed around just like any other data type. For instance, if I evaluate whether '2 is greater than 3,' it returns false.
00:15:44.440 Then, this result is processed through a keyword message, invoking the boolean logic of true or false depending on the output. The implementation of this logic could be interesting.
00:16:20.410 Now, let's look at the Smalltalk system browser, which is how you interact with your code. This system browser provides access to all the code in Smalltalk, including the code that runs the browser itself.
00:16:48.080 The left pane represents packages, while the right side shows all the classes and methods. You can explore boolean objects to reveal the methods associated with true and false.
00:17:11.590 In the case of conditional logic, if a method under the boolean class is invoked, it evaluates the appropriate block—either true or false—based on the condition.
00:17:36.210 Similarly, loop logic in Smalltalk resembles Ruby, where you can employ collection classes along with methods that accept blocks, allowing the evaluation of items one by one.
00:18:04.540 I would like to demonstrate a test-driven development cycle in Smalltalk with a very simple example. This involves creating a fraud detection system that checks if two user emails are equivalent by canonicalizing them.
00:18:40.400 To begin, I’ll create a test class called 'TestFraudUser' within the designated package. In this, I can establish a skeleton for my test method, defining temporary variables and assertions.
00:19:11.630 For example, the first test checks a basic email format. Once I accept these structures into the system, I can use a new user instance and assign an email address to it.
00:19:35.570 Now, I’ll assert that when fetching the canonical email for this user, it matches the original lowercase format. This prompts the system to create any classes or methods that don't exist yet.
00:20:04.470 At first, it indicates that there isn’t a method for canonical email. After accepting the message, I'm prompted to create it.
00:20:25.440 Once I define that, I can return the email to the caller, and when I run the test again, it should pass, confirming everything is functioning correctly.
00:20:46.630 You should note that the test runs instantaneously after making changes since the system is already running, allowing rapid experimentation.
00:21:16.200 Now, for the second test, I simply need to modify the original test to check case sensitivity. Testing both lowercase and uppercase letters ensures that they yield the same canonical email, filtering out discrepancies.
00:21:41.520 After running the modified test, it will initially fail because the email case doesn't match the expected output. I can adjust this by leveraging methods from the Smalltalk string library to convert the email to lowercase.
00:22:02.580 After making this final change, running both tests again shows they return green without any assertion failures. This highlights how smoothly Smalltalk integrates with test-driven development.
00:22:23.440 I expect that this session has given you a taste of what it's like to work with Smalltalk. One significant advantage is how it eliminates the startup time typical of other environments.
00:22:56.620 However, if Smalltalk is that impressive, why don’t we all use it? What transpired is that the elements Smalltalk excelled in became less important over time.
00:23:24.420 While programming languages that adapted to new demands and integrated well with other ecosystems have gained favor over Smalltalk, it's worthwhile to appreciate its unique strengths.
00:23:39.060 That's my introduction to Smalltalk. If anyone has questions, I'm available to discuss them. You might also wonder about how I prefer to focus my attention on Smalltalk rather than discussing more obscure languages.
00:24:06.150 In conclusion, I appreciate your time and enthusiasm. I hope you enjoy the rest of the conference.
00:24:30.240 Thank you for your attention. I look forward to continuing our discussions about Smalltalk, especially as we delve into the topic of MagLev next.
Explore all talks recorded at MountainWest RubyConf 2014
+12