Skip to content

Instantly share code, notes, and snippets.

@bzz
Last active December 7, 2018 17:24
Show Gist options
  • Select an option

  • Save bzz/d5cff64deb63e0b73f891a6e3bcca149 to your computer and use it in GitHub Desktop.

Select an option

Save bzz/d5cff64deb63e0b73f891a6e3bcca149 to your computer and use it in GitHub Desktop.
Open Source Day: learning Smalltalk

OSD #8

TL;DR: Learning Smalltalk

Objective

  1. Run Pharo http://pharo.org/
  2. Use Moose http://www.moosetechnology.org/
  3. Try SmaCC https://github.com/ThierryGoubier/SmaCC

Main sources:

Learning Smalltalk

0. Installing & Launching Pharo VM

brew cask install pharo-launcher
# Chose Moose 6.0
# follow http://themoosebook.org/book/index.html#h1mooseinanutshell
Pharo6.0.app/Contents/MacOS/Pharo Pharo6.0.app/Contents/Resources/Pharo6.1.image

I. Simple Smalltalk program

World (click) -> Playground

ProfStef go. (cmd+d to evaulate, using "Do It")

a := OrderedCollection new
  add: 1;
  add: 2;
  add: 3;
  yourself.

a. (cmd+p to print)

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.


a := OrderedCollection new
  add: 1;
  add: 2;
  add: 3.

Transcript show: a.

Playground/workspace: "Do it", "Print it", "Insepct it" Transcript as console.log or System.out System Browser message or cmd+b Spotter - just Shift+Enter

  • #class
  • #implementor

II. Code visualization using Moose

  • Extract the data, build model

    wget .../jdt2famix-bin-1.0.3.zip
    unzip jdt2famix-bin-1.0.3.zip
    git clone --depth 1 git@github.com:rastaman/argouml-maven.git
    cd argouml-maven
    mvn dependency:copy-dependencies -DoutputDirectory=dependencies -DoverWriteSnapshots=true -DoverWriteReleases=false
    ../jdt2famix-1.0.3/jdt2famix.sh
    
  • Open Moose: World (click anywhere) -> Moose

  • Load the model: MSE (right corner) -> coose "argouml-maven.mse"

  • Select just loaded "argouml-maven" model

  • Select "All methods"

  • Visualize all/@Deprecated methods

    view := RTMondrian new.
    
    view shape circle
    	if: [ :each | each isAnnotatedWith: 'Deprecated' ]
    	color: Color red.
    	
    dep := (self, ( self flatCollect: #clientTypes ) ) asSet.
    
    view nodes: dep.
    view layout grid.
    view

III. Simple parser using SmaCC

  • World (click anywhere) -> Tools -> SmartCC Parser Generator
  • Simple grammar
    <number> : [0-9]+; 
    <whitespace> : \s+;
    
    Expression 
    	: Expression "+" Number
    	| Number
    	;
    Number 
    	: <number>
    	;
    
  • add Scanner/parser names
Options -> Scanner Class
Options -> Parser Class
  • File -> Save
  • Test tab
    3 + 4
    
    Validate: (Select text) -> Evaluate Inspect AST: (Select text) -> Inspect

IV. add Smalltalk to Excercism.io

Apps

Articles

Learnings

 + image-based approach to programming (Docker/VirtualBox)
 + everything is an _object_ (blocks, control structures, etc) that sends _messages_
 + Less is more: No type declarations, no primitive objects,
    no generic types, no modifiers, no operators, no inner classes,
    no constructors, and no static methods
 + Awesome tooling: System Browser, Spotter
 + at least single VM tree: https://github.com/OpenSmalltalk/opensmalltalk-vm
 + Existing grammars in SmaCC: JS, Java, C/C#, etc

 - fragmentation of the world: VisualWorks, Dolphine, Squeak, Pharo, GemTalk,  ... 
 - external Pharo-launcher to manage VMs/Images that the OS app loads
 - no propper default keybidings support for editors :/ 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment