Smalltalk Language

Naming Convention

A programmer whoever used C language knows that it's easier to define a user identifier which begins with lower caps and make each word's first letter capital when it's combined by more than one word. Surely, these are merely recommendations and C language itself doesn't require to follow these rules. In Smalltalk world, these become requirements.

As I wrote in the previous chapter, libraries spans more portion of a Smalltalk system than the language itself. Therefore, system identifiers don't differ from user identifiers. Instead, Smalltalk distinguish local definition from global definition by the leading letter. A capital letter leads a global declaration(class, method or variables) while a lower caps letter leads a local declaration.

In addition to that, Smalltalk doesn't allow to use special characters in an identifier. For example, "_fileName" is wrong name for any definition in Smalltalk. Honestly, this restriction makes us a little bit inconvenient but there's less possibility to make a spaghetti code like C/C++ by this rule.

Following definitions are mostly provided by Smaltalk library rather than the language.

Literals and Constants

Smalltalk defines couple of different sort of literals. The first one is numbers which we can directly put anywhere in the code.

123       3.14         2.789e31              33/8      -0.07

Secondly, there's string. It's just straightforward. A string is surrounded by a pair of single quotation marks.

'semgl'
'allther'
'Hi, there!'

It's interesting that you can list up individual letters which put together with leading dollar cost sign.

$s $e $m $g $l

Symbols are also literal. Symbols are similar to #define, enumerated of C or const definition of Pascal. A symbol always begins with # .

#red               #syndicateList             #waiting

Smalltalk also has a definition of collection and it becomes a symbol when # was put in front of it.

#(2  7.59  'Hello'   #resetPending)

The above collection has various types of elements in it. We'll discuss about it later.

Finally, There are three special constants in Smalltalk.

true        false         nil

These are used to refer an instance of a class. 'nil' means nothing.

Pseudo Variables

Besides six variables types which will be explained in the next chapter, we have two special variables. Those are called as pseudo variables. They are self and super.
Well, it's hard to say these guys as variables since those are not defined by user but the values of these vary depending on calling location. In that sense, we can still say those variables.

self means an object itself. Precisely, self refers the object itself when we use it inside the object definition. Smalltalk requires to send an object message to execute a method. The only way to call a method of a object inside the object is to use self.

super is similar to self except the referred object is super class type(definition). Thus, we can use it when we want to use super class's definition instead of the overridden method of the child class. It's useful when a functionality becomes complicated. We may define a simple method in super class and extend it by overriding in child classes.

Previous
Table of Contents
Next

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License