Portability in Seaside
   NYC Smalltalk
 December 10, 2009
Julian Fitzell


Co-creator of Seaside
Independent consultant
694 classes
6844 methods
Platforms
External Interface Support
                  XML Support enables XML–Smalltalk object
                  mapping, includes a server interface via XML
                  request handlers and reading of remote resources
 B disk           via TCP sockets using HTTP requests
                  OLE Support enables an application to use OLE
                  clients and custom control services.
                  Domino Connection allows an application to
                  retrieve and work with Domino documents as well
                  as access Notes mail system.




                    Download a risk-free trial copy:
                www.instantiations.com/VAST/download




m/VAST
                                                   Build Quality Software

 l other trademarks mentioned are the property of their respective owners.
Portability



Photo: Alexia´s, flickr.com
Goals

Create consistent experience
Minimize platform changes
Isolate platform changes
Ease code updates (in both directions!)
Namespacing:

  WAObject
 #seasideUrl
Syntax



Photo: pipp, sxc.hu
n o
  Underscore
  Assignments

      a_1
      b←2
n o
  Brace Arrays

      { 1. 2. 1 + 2 }
n o
Array Constructors

 #[ ‘string’, 123, Object new ]
n o
  Byte Arrays

      #[ 1 2 3 ]
n o
 Variable Bindings

   {Smalltalk.Object}
n o
 Selection Blocks

   {:i | i.is.permanent}
o k   Pragma

  <javascript: 1.5>
ANSI



       Photo: njd89, sxc.hu
ANSI Protocols
Object, Character, Boolean, nil, etc.
Block
Exception
Numeric
Collection
Date and Time
Stream
Exceptions



Photo: ingythewingy, flickr.com
Exception Protocols

 #signal, #signal:, ...
 #on:do:, #ensure:, #ifCurtailed:
 #defaultAction, #isResumable
 #pass, #outer, #retry, #resume
 Warning, Error, Notification, ZeroDivide, ...
n o
[ ... ]
 on: Error
 do: [ ... ]
y e s
[ ... ]
 on: Error
 do: [ |err| ... ]
n o
 #defaultAction
       +
 non-resumable
   exceptions
“The exact behavior and
  result of this method is
implementation defined.”
Unless the exception is resumable,
“the action taken upon completion
  of the #defaultAction method is
      implementation defined”
n o
MyException signal
Collections




Photo: ijsendoorn,sxc.hu
Collection Protocols

 Array, Set, OrderedCollection, Interval, ...
 #do:, #collect:, #select:, #reject:, #detect:, ...
 #includes:, #isEmpty, anySatisfy:, ...
 #asSet, #asOrderedCollection, ...
 #at:put:, #at:ifAbsent:, #removeKey:, ...
n o
 Collection>>#=
n o
 #withIndexDo:
y e s
 #keysAndValuesDo:
n o
  #pairsDo:
y e s
1
    to: aCollection size
    by: 2 do: [ :i | ... ]
Strings




Photo: Lynne Lancaster, sxc.hu
n o
 Symbol is a String
n o
      #match:
n o
 Object>>#asString
n o
 #displayString
n o
 Non-ASCII Strings
Streams




Photo: Lynne Lancaster, sxc.hu
Stream Protocols

ReadStream, WriteStream,
ReadWriteStream
#close, #isEmpty, #position, #reset, ...
#do:, #next, #peek, #upTo:, ...
#cr, #nextPut:, #nextPutAll:, ...
n o
 #next, at the end
   of a stream
y e s
 Check #atEnd first
n o
  #position
  #position:
Times
                        and
                      Dates




Photo: inya, sxc.hu
y e s
  DateAndTime
       +
    Duration
n o
  TimeStamp
k in d a

           Time
s o r ta

           Date
Cross-Platform Behaviour


        Consistent
        Conflicting
         Missing
Unit
               Slime       Grease
 Tests


Consistent    Conflicting   Missing

  Use it!      Avoid it!   Add it!
 (Test it!)
Unit Tests




Photo: shadowkill, sxc.hu
Done?
Unit Tests



150
                                                   131




                        44            44

          20

  0
      Seaside 2.5   Seaside 2.6   Seaside 2.7   Seaside 2.8   Seaside 3.0
Unit Tests
1,200




                     1,115




1,050
Slime
  Lint Tests
for Seaside




               Photo: A Syed, sxc.hu
Rules to detect
Portability Issues
a _ 1.

b := { a + 2. 3 }.

c pairsDo: [ :a :b | a raisedTo: b ]
a _ 1.

b := { a + 2. 3 }.

c pairsDo: [ :a :b | a raisedTo: b ]
a _ 1.

b := { a + 2. 3 }.

c pairsDo: [ :a :b | a raisedTo: b ]
a _ 1.

b := { a + 2. 3 }.

c pairsDo: [ :a :b | a raisedTo: b ]
Rules to detect
 Seaside Bugs
html div
  with: ‘Hello World’;
  id: ‘message’.

html updater
  id: ‘message’;
  callback: [ :r | html text: ‘Bye’ ]
html div
  with: ‘Hello World’;
  id: ‘message’.

html updater
  id: ‘message’;
  callback: [ :r | html text: ‘Bye’ ]
html div
  with: ‘Hello World’;
  id: ‘message’.

html updater
  id: ‘message’;
  callback: [ :r | html text: ‘Bye’ ]
Grease
   Platform
Compatibility
      Layer




                Photo: DarkSide, sxc.hu
Pragmatic
Minimal
Unit Tested
ANSI++
Grease Features

Consistent object initialization
Consistent exception signalling
Common convenience methods
Platform-dependent behaviour
Unit tests
y e s
GRObject class>>#new
	 ^ self basicNew initialize
y e s
GRError class>>#signal

 “VW implementation”
	 ^ self raiseSignal
y e s
Object>>#greaseString

 “Squeak implementation”
	 ^ self asString
y e s#trimLeft
    #upToLast:
       #ifNil:
   #isCollection
y e s
GRPlatform current
	 base64Decode: 'aGk='.
GRPlatform current
	 addToStartupList: SomeClass.
GRPlatform current
	 openDebuggerOn: anException.
Packaging

                                ↑

                                SUnit




Photo: Tory Byrne, www.sxc.hu
73 Packages
Common

Seaside-Core
Platform-Specific

Seaside-Pharo-Core
Test

   Seaside-Tests-Core
Seaside-Tests-Pharo-Core
BON US!



  Find incorrect layer
     dependencies
Monticello
Monticello

Declarative modeling
Distributed repositories
Optimistic code merging
Vendor round-tripping
Monticello

☹   Slow with large repositories
☹   Inconvenient with many packages
☹   Awkward when renaming and moving
    between packages
Future?
Metacello

Declare and load package configurations
Express dependencies on other projects
Easily upgrade to newest versions
Mason


Automate build process
Run tests for each package + dependencies
Monticello2

Faster
Per-method version history
Better interface for projects with many
packages
Easier to port? (uses Grease)
book.seaside.st
Summary
Write tests!
Avoid extended syntax
Use ANSI where possible
Package out platform-specific code
Slime/Lint for what you can’t use, Grease for
what you can
www.seaside.st
  blog.fitzell.ca
jfitzell@gmail.com

Seaside Portability