Part 1

Objectives

  • Create a SSH id.pub file and submit it
  • Download and run the Pharo Smalltalk enviroment

Steps

  • Fossil
  • SSH
  • Downloading and running Pharo

Introduction to Fossil

Fossil is a Distributed Version Control System (DVCS) designed to help you manage and maintain your source code, as well as collaborate on it with others. Fossil can help you track what's change in your source code, move it around to different machines you're working on, let you and a friend work on the same code and then merge your changes, and much more. Microsoft, Google, Apple, Mozilla and every other organization use a VCS, and you should too! There are other Distributed Version Control Systems such as Git and Mercurial that have their fans. (Git is the most widely used, but actually isn't the best to use for human-sized projects. Fossil has many attributes that make it work particularly well for small teams.)

You will have a personal Fossil repository for CPS506. The instructions for accessing it will be here shortly.

Introduction to SSH

SSH is a secure way to communicate between computers. Fossil uses it to access your central repository. All you need to do to set that up is:

  1. Make sure you have a id.pub (first part of the name doesn't matter) file. You may already have one in your .ssh directory on the moon (you should check), or (equivalently an authorized_keys file). If not, create one on your remote computer, copy it to the moon, make a .ssh directory, put the file in that directory.
  2. On a moon do:
    submit-cps506 .ssh/id.pub
    or
    submit-cps506 .ssh/authorized_keys
  3. Introduction to Pharo

    This lab uses material from Chapter 2 of Updated Pharo by Example (http://files.pharo.org/books/updated-pharo-by-example). Portions from that text are used under the CC BY-SA license.

    Pharo is a GUI-based programming enviroment for the Smalltalk programming language. Smalltalk is one of the first languages designed for object-oriented programming in the late-70s and early 80s.

    Smalltalk is based on a virtual machine, similar to Java, which interprets bytecode and makes it platform independant. One of the unique features of Smalltalk is that all developement and changes are done in the Smalltalk enviroment itself. All classes (including their code) and objects (including all of their state) are stored inside an Image that saves the complete state of the system. When you save the image, close the VM, and then re-open it again, perhaps on another machine, everything will be exactly as you left it.

    Downloading and running Pharo

    Simply go to Pharo.org and got to the Downloads page to get a launcher for your platform.

    Open that and you will be able to create a new image.

    Part 2

    Objectives

    • Gain a grasp of the basics of Smalltalk programming
    • Implement a simple Smalltalk class

    Steps

    • open the image you created in Step 1
    • The playground as a repl
    • The tutorial
    • A simple Caesar Cipher
    • Filetree and submitting your code

    Introduction

    Open Pharo again and everything should be as you left it (remember the image from Part 1?).

    Time to Play

    The playground is an enviroment in the Smalltalk world that lets us run (evaluate) expressions and potentionally see the results.

    Click to open the world menu and select playground. Try entering the following code:

    ProfStef go.

    This sends the go message to the class (object) ProfStef. Everything in Smalltalk is composed of objects and messages. There are three types of messages: Unary, Binary and Keyword.

    Try hightlighting the code, right click and choose do-it. This opens the built in Smalltalk tutorial. Go ahead and work your way through the rest of the tutorial which will introduce you to Smalltalk.

    Caesar Cipher

    The Caesar Cipher is a simple substition cipher known to have been used from at least the time of Julius Caesar. To encrypt a message (plaintext) we take each letter in the message and switch it with the 3rd letter that follows it in the alphabet, wrapping back to the begining if we go off the end. To decrypt an encrypted message (ciphertext) we simply reverse the process.

    Write a simple Caesar class with encrypt and decrypt methods which take a string and returns a string which is the encrypted/decrypted message. Start by opening the class browser, right clicking and choosing add class. When you add the class, specify the package as: 'CPS506-lab1'.

    • In the category initialize-release
      initialize
          n:= 3.
        
    • In the category encrypt
      encrypt: aString
          "encrypt a string using the caeser cipher"
          |array|
          array:=aString asByteArray.
          ^(array collect: [ :each | each + n ]) asString.
        
    • In the category encrypt
      decrypt: aString
          "decrypt a string using the caeser cipher"
          |array|
          array:=aString asByteArray.
          ^(array collect: [ :each | each - n ]) asString.
        

    After adding the appropriate methods, you should be able to use your class from the playground with code similar to:

    |aString|
    aString:=Caesar new encrypt: 'CAESAR'.
    Transcript show: aString.

    Which ouputs 'FDHVDU' on the Transcript. Chapter 11 of Pharo by Example maybe useful for it's coverage of Collections and Iterators in Smalltalk.

    Packages, Montecello and Filetrees

    As you have read, code in Pharo is organized into packages. When you open the System Browser, all the packages in the system are displayed on the right. Make sure the code for your Caesar class resides in a package with the name CPS506-Lab1.

    Pharo has it's own built in version control system called Montecello, which works well for code that lives inside the Smalltalk image (a.k.a everything in Pharo). However, complications arise when we want to interface Pharo's image based model, with a more traditional file based model, such as is used by Unix and Fossil. To bridge the gap, we use a plug-in called Filetree.

    Now open the Montecello browser from the World menu. As you can see, Montecello maintains a list of packages along with their versions. We are going to create a new version of our CPS506-Lab1 package and save it to a Filetree repository (i.e. a directory). First, select your package from the left and then click on repository. Select Filetree:// from the pop-up and then select the Monticello folder into which you will save the package. Now you should see the filetree repository listed on the right pane of the Montecello browser. Finally, click save to create a new version and enter a comment (perhaps, Inital version).

    If you browse to the directory, you can see that Filetree has created a tree of .st files to represent the methods of your Smalltalk classes, along with some accompanying metadata. This can now be commited to Fossil.

    You should verify that you successfully uploaded your files to the course repository by visiting your page again and examining what is stored there.