Monday 16 November 2015

Hello World

Transcript show: 'Hello  World'

Which means:
On a Transcript object, show the string 'Hello World'

The Transcript object is a display window, logging results and displaying them.

If we send a specific string to a Transcript, with a polite request to show it, the Transcript object will (hopefully) respond appropriately.

So
   Transcript (the class) is asked to
   show:
   'Hello World'

We can ask politely in three different ways in Smalltalk - i.e. we can send three types of message in Smalltalk.

The message can be a single part. Known as a  'Unary' message.

The message can have two parts - a 'Binary' message.

The message can have multiple named parts - a 'keyword' message.

Keyword messages come in paired parts.
A request name or a parameter name - the keyword -
   followed by
an argument (aka a parameter)

The request's (or message's) name has a colon at the end of it.

The argument is an object.  (Or to be pedantically technical, the object's given name.)

Because everything in Smalltalk is an object, the argument (or parameter) can be as simple or complex an object as you like.

It can be as simple as an integer number (as all the integers are objects).

It can be as complicated as a huge agglomeration of other, smaller objects.

Perhaps an object representing a person, with strings for the person's name, and age and date of birth and place of birth, and lists of every type of medicine the person has ever been prescribed, and when, and a set of schedules of when the patient should be taking their current medication, and freeform notes on what the next treatment steps might be, and a running count of the number of face-to-face treatment visits the person has had, and a dictionary of the person's symptoms, and, and, and

You can even create unnamed objects on-the-fly, complete with new code to execute, and hand these over as parameters.

These spontaneous, anonymous objects are known as 'blocks', and they'll become idiomatic later on.

So Transcript show: 'Hello World'
is a keyword message.

Transcript is the object receiving the request.  In this message, Transcript is the receiver.

show: is the keyword.
We can tell it's the keyword in two ways.
It's between the receiver and the argument.
It ends in a colon.

'Hello World' is the argument or parameter.  It's an object.  In this case, a String object.

Keyword messages can have several keywords, e.g.

theAuthorsPetExampleOfAnObject 
   firstKeyword: anObjectBeingUsedAsAParameter
   secondKeyword: anotherObjectBeingUsedAsAParameter
   thirdKeyword: yetAnotherObjectBeingUsedAsAParameter .

This message has a receiver, an object which receives the message.
The message has three keywords.
The message has three parameters.

Messages are also known as methods.  Strictly speaking, a message is a request, and a method is how an object responds to the specific request.

For instance, if a boss says 'Jump!', perhaps the response they are looking for is for you to say 'How high?'

The message they have sent you  is 'Jump!'.  Your method of responding to a 'Jump!' request may be to say 'How high?' back.  Perhaps your chosen method of responding to a 'Jump!' message is to leap up into the air.

In any event, we can use the word's 'method' and 'message' somewhat interchangeably.  One thing's message send is another thing's method of responding.

So the method's name in our example is
firstKeyword:secondKeyword:thirdKeyword:

To write the method's name out in full, we'd place a pair of >'s to separate the end of the name of the Class of objects from the start of the name of the first of the keywords.

AuthorsPetExampleOfAnObject>>firstKeyword:secondKeyword:thirdKeyword:

The convention is to have object's names and methods begin with a lower-case letter, and have Classes and their methods have names beginning with Upper-case letters.  In the wild, Classes will always have an InitialUpperCaseLetter, but their Class methods often don't.

To execute the code, open up your Smalltalk, e.g. Pharo, Squeak, Dolphin, Cincom, Cuis  Smalltalk.

If you have a two or three button mouse, click the left-button on the window backdrop.
If you have a single button mouse, click on the window backdrop.  (This type of click is called an action-click).

This brings up the World Menu.  Select Transcript.

Action-click again, and select Workspace (which is named Playground, in some Smalltalks).


Type in the code in the Workspace.  Select it.  Right-click on the highlighted text, if you're using two (or three) button mouse.  (If you are using a single button mouse, there will be (a) key(s) to press a the same time)

Then select 'Do it'.

Hello World will appear in your Transcript window.




Beginning to Smalltalk - A Beginner's Smalltalk Tutorial series

I'm hoping this blog will become an ordered sequence of tutorial posts.  They're intended for people just beginning Smalltalk.  Perhaps even beginning to learn how to develop applications for desktop computers.

Smalltalk is wonderfully cross-platform.  I write my own applications on Windows on a PC, and on Linux on a Raspberry Pi.  As I write them, I am completely relaxed that they can be used by people who prefer Apple Macs, and it's perfectly possible to write applications that run in a web-browser.

I'm personally working on writing Smalltalk applications that manage, control and distribute multi-platform mobile apps written in JavaScript.

I've been making posts for myself in the Smalltalk in Small Steps blog.  Generally little 'aha' moments, or "I really must keep that filed for later when I need it" posts.

My plan is now to tidy up those posts, put them into a sensible sequence, and verify they are useful on several different Smalltalk platforms.

I hope they'll become more generally useful to the Smalltalk community.  Most importantly, I hope they'll become useful to the potentially much larger audience of people who don't know much, if anything about Smalltalk, and who are interested in knowing more.

If this blog is useful to you, I'd be very interested to hear from you about your own plans for learning Smalltalk - why you want to learn it, what you want to do with it, and how you get on with learning it.

It's a fabulous learner's language - and once you know Smalltalk, it makes it easier to understand the deeper patterns of object-oriented work you might do in Java, Objective C, Ruby or Python.

Good luck!

My email is euanmee at a well known email service run by Google - gmail.com

Sunday 15 November 2015

How to get a Smalltalk up and running

Scope: This how-to covers Squeak, Pharo, Cuis, Amber and Dolphin.  

Many of the concepts also apply other Smalltalks. 

Smalltalk installations come in two principal parts.

The first part is known as the "Virtual Machine" 

More usually called the "VM".  This is the underlying engine that Smalltalk runs on.  It interfaces with the operating system of the computer that you are running the Smalltalk on, and also provides low-level services e.g. garbage-collection. 

Most Virtual Machines are cross-platform.  When you use a cross-platform VM, all the Smalltalks that run on top of the VM are cross-platform too. 

Cuis, Pharo and Squeak can all run on the same Virtual Machines, which run on MacOS, Windows and Linux.  

Dolphin Smalltalk is designed to run on its own Virtual Machine, which runs on Windows. 

The second part is called the "image" .  

The image holds a bunch of Smalltalk code.  And it holds more, too. It holds a bunch of data.  And it holds all the information about the Smalltalk GUI as it was when the image was last saved.  Which windows the user had open, and where they were positioned. 

It holds everything that Smalltalk knew about, and all information relevant to running the Smalltalk installation. 

The image file can be considered to be a collection of all information about a particular installation of  Smalltalk from just before it went into hibernation. 

Choosing a Smalltalk 

A little bit about each Smalltalk, and platform-specific notes

Squeak has given rise to both Pharo and Cuis, and also both the Seaside and AidaWeb web applications frameworks, along with much else.


The Scratch graphical programming language is written in Squeak, for example.

A lot of work goes in to getting Squeak running fast on the Raspberry Pi , because Scratch is written in Squeak. Scratch is a key package for teaching children to program, and the Rasberry Pi is a platform designed for teaching children to program. This work is done so that Scratch will run fast on the Pi, but it has a very useful side-effect for people who want to use Smalltalk on the Pi.

Cuis is a fork of Squeak, intending to radically simplify the numbers of libraries in the distribution, and radically simplify the way GUIs are drawn and coded.

It contains only 500 classes, compared to the 2,300 in Squeak and the 5,000 in Pharo.

This makes it a good candidate for understanding a Smalltalk from top to bottom. Potentially it might lead to speedy performance.

Pharo is a fork of Squeak where the focus is on extending the functionality and ability of Squeak, without much regard to backward compatibility.  Considerable effort goes in to making sure that Pharo always remains a capable platform for the Seaside web server.

Pharo evolves rapidly, with vast majority of the additional functionality added by academic computer science research groups.  Nonetheless, the Pharo management team intend it also to be a useful platform for commercial application developments - as can be seen by the effort that goes into keeping the GUI and desktop themes looking clean and professional.

Cuis, Pharo and Squeak can all run on the same Virtual Machines, which run on MacOS, Windows and Linux.  

Squeak 5.0 includes extensive optimisations for when it runs on the Raspberry Pi


Dolphin Smalltalk is designed to run on its own Virtual Machine, which runs on Windows

The key advantages are that Dolphin is designed to provide a Windows native look-and-feel; and a working system can be packaged up as a .exe install file. This means there is no learning curve for Windows end-users when they are installing an end-user app written in Dolphin Smalltalk. 


Dolphin Community Edition cannot store code and classes to repositories in the cloud, or automatically retrieve packages from the internet.  Downloading packages that other people have already written for you to use from the internet is really useful as you start out. So you'd be better to download Squeak or Pharo, to start out with - unless you really want native look-and-feel from day 1.    

Downloading packages from the internet is available in the paid-licence version of Dolphin.  I have not yet used this, so cannot vouch for how well it works.

So unless you want to learn only Windows-GUIs, I personally advise you to start on a different Smalltalk, and then later come back and learn the Windows-GUI facilities in Dolphin, once you are used to Smalltalk.

Amber Smalltalk runs in your web-browser.
This makes it really convenient for trying code snippets, anywhere. 
It also allows you to write JavaScript apps in Smalltalk.  These apps happily integrate with the rest of the JavaScript ecosystem.
 

If you want to start writing web applications as you learn, then you can use a package called Seaside, which has a once-click installer for Pharo and Seaside, all in one step. 

Seaside will also run on Squeak, but I don't know of any current All-in-one installer for it.

Licencing Issues

Cuis, Pharo and Squeak all use the MIT licence.  This allows commercial use, and is also GPL-compatible. 

Dolphin's licence allows you to distribute the DLLs and the Dolphin VM as an integral part of executable applications created by you using Dolphin Smalltalk. 

Download a  Smalltalk

With all Smalltalks

If you have a specific pre-existing application, package or library you want to use, you may need to use an older version.  If you just want to get started with the latest version, choose the latest version. 

On Windows

All of the cross-platform Smalltalks can be installed as a 'portable' installation.  You can copy the installed folder to anywhere on your PC and the Smalltalk will still run. The folder contains all the necessary code and .dlls to run successfully. 

For specific Smalltalks

Amber:

Go to http://amber-lang.net

Click on the "Try Amber in your Browser" link.

Cuis:

Cuis currently has you download the Smalltalk VM and the Cuis image separately. Probably best to start with one of the others, then come back to Cuis once you have got the hang of  VMs and Images. 

The Cuis Image is available from 
https://github.com/Cuis-Smalltalk

Any Squeak VM should work with Cuis. 


Dolphin:

http://www.object-arts.com/downloads/downloads.html 

Dolphin Smalltalk download page


At time of writing (2015-11-11), there is one download link 
Dolphin X6.0 (Community and Pro Editions) 

This downloads a .exe file.   (And the first time it runs, it will prompt you to email for a (zero-cost) Community edition licence number). 

If later you wish to prepare .exe files for your application's end-users, you can upgrade to the Pro Edition for a fee of ~£160(GBP) or approx.  $225(USD)/€225(EUR) 



Pharo: 



At time of writing (2015-11-11), the site offers Pharo 4.0 via three download links, one for each of MacOS, Windows and Linux. 


Windows : http://files.pharo.org/platform/Pharo4.0-win.zip
Linux : http://pharo.org/gnu-linux-installation

Once you have a little experience with VMs and images, you can download the latest Pharo 5.0 development image from  http://files.pharo.org/get-files/50/pharo.zip


Seaside



Squeak:

http://squeak.org/downloads/ 



At time of writing (2015-11-11), there are two versions listed under "Quick Download" 
All-in-One (Spur)  - Version 5.0 
All-in-One (Non-Spur) - Version 4.6 

"Spur" / "Non-Spur" refers to the Virtual Machine (VM) included in the download.  Cog is currently the most prevalent VM in the Squeak/Pharo/Cuis worlds. 

A recent improvement to Cog was labelled "Spur".  So '(Spur)' means that the install includes the latest Cog VM with added Spur.  '(Non-Spur)' means that it includes a slightly older version of the Cog VM. 

To start A Smalltalk

Once you have the files unzipped and installed on your computer: 

For Amber

If you followed the installation guide, you already have it started!

For Cuis

On Windows 
Open the folder with the VM in it. 
Drag the Cuis .image file you want to use and drop it on the VM 

On Linux

To be determined. If anyone knows how, please let me know, and I'll include it here. 

on MacOS

To be determined. If anyone knows how, please let me know, and I'll include it here. 


For Dolphin (Version 6)

On Windows 
Open the folder you have installed Dolphin to. 
Drag the 'Professional (Fresh Install).img' file and drop it on Dolphin.exe


For Pharo 4.0

on Windows 
Open the folder you have unzipped Pharo to. 
drag the .image file you want to use and drop it on Pharo.exe 

On Linux 
Move to the folder you have unzipped Pharo to 
In a shell or terminal window, type: 
./PharoS Pharo.image & 

on MacOS 

To be determined. If anyone knows how, please let me know, and I'll include it here. 



For Seaside 3.1

on Windows 
Open the folder 
Double-click on Pharo.exe

On Linux 
To be determined. If anyone knows how, please let me know, and I'll include it here. 



on MacOS 


To be determined. If anyone knows how, please let me know, and I'll include it here. 



For Squeak 5.0

on Windows 
Open the folder you have unzipped Squeak to. 
Double-click on squeak.bat 

on Linux 
navigate into the Squeak folder  
In a shell or terminal window, type: 
bash squeak.sh 

on MacOS

To be determined. If anyone knows how, please let me know, and I'll include it here. 
I imagine you double-click on Squeak-5.0-All-in-One.app 


Version 0.9, published 2015-11-12