Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Smalltalk

 Smalltalk

I'm a Rubyist. I know nothing about Smalltalk. I explored.

Avatar for bjhess

bjhess

June 08, 2012
Tweet

Other Decks in Programming

Transcript

  1. MUSTACHIOED ALAN KAY Xerox PARC What have you done for

    me lately? Kids toys: Squeak, Tweak, OLPC-OMG DAN HENRY HOLMES INGALLS, JR. Xerox PARC What have you done for me lately? Squeak, Distinguished Fellow Engineer Scientist Beach Enthusiast
  2. ADELE GOLDBERG Xerox PARC We don’t hear much about her!

    Helped develop Smalltalk-80, wrote much of the documentation, helped develop design templates (forerunners to design patterns)
  3. So it goes: 1. Parentheses 2. Unary messages 3. Binary

    messages 4. Keyword messages 5. Left to right
  4. “Expression Separators” Transcript cr. Transcript show: ‘Hi’. Transcript cr “Message

    Cascades” Transcript cr; show: ‘Hi’; cr Functionally Equivalent
  5. [ :x | 1 + x ] value: 2 ->

    3 “block with one parameter”
  6. [ :x :y | x + y ] value: 1

    value: 2 -> 3 “block with two parameters”
  7. [ :x :y | x + y ] value: 1

    value: 2 -> 3 # in ruby?
  8. # [ :x :y | x + y ] value:

    1 value: 2 (lambda {|x, y| x + y}).call(1, 2) # in ruby?
  9. [ 1 + 2 ] -> 3 “even this block

    has an implicit message”
  10. [ 1 + 2 ] value -> 3 “even this

    block has an implicit unary message”
  11. ( 17 * 13 > 220 ) ifTrue: [ 'bigger'

    ] ifFalse: [ 'smaller' ] -> 'bigger' “if/else”
  12. result := String new. 1 to: 10 do: [:n |

    result := result, n printString, ' ']. result -> '1 2 3 4 5 6 7 8 9 10 ' “to:do: on integer”
  13. result := String new. 1 to: 10 do: [:n |

    result := result, n printString, ' ']. result -> '1 2 3 4 5 6 7 8 9 10 ' “to:do: on integer” SZUPER ÜBERLOOPIN’
  14. A method! greet: name | message | message := 'Hello

    ', name. Transcript show: message.
  15. Also: All methods are public. A trait is like a

    Ruby module. You can remove and alias methods in a trait at the time you add it to your class. Traits came after modules. Traits don’t depend on order of inclusion.
  16. # ruby service = WeatherForecastService.for_location "Toronto" forecast = server.forecast_for_days(5, "xml")

    “smalltalk” service := WeatherForecastService forLocation: 'Toronto'. forecast := service forecastForDays: 5 format: 'Xml'
  17. # ruby service = WeatherForecastService.for_location "Toronto" forecast = server.forecast_for_days(5, "xml")

    “smalltalk” service := WeatherForecastService forLocation: 'Toronto'. forecast := service forecastForDays: 5 format: 'Xml'
  18. # ruby service = WeatherForecastService.for_location "Toronto" forecast = server.forecast_for_days(5, :format

    => "xml") “smalltalk” service := WeatherForecastService forLocation: 'Toronto'. forecast := service forecastForDays: 5 format: 'Xml'
  19. # ruby if [] puts 'true' else puts 'false' end

    “smalltalk” (1 = 1) ifTrue: [Transcript show: 'True'] ifFalse: [Transcript show: 'False']
  20. # ruby def with_blocks(block1, block2) block1.call block2.call end with_blocks(proc{ 1+1

    }, proc{ 2+2 }) “smalltalk” aBlock: block1 anotherBlock: block2 block1 value. block2 value. aSomeObject aBlock: [ 1+1 ] anotherBlock [ 2+2 ]
  21. Smalltalk is a written entirely in a virtual machine: View

    source code while app is running. Close your VM, image saved to disk. Open VM, starts up in the same exact state.
  22. Smalltalkers love living in the VM: Dynamic language, but solid

    refactoring. Great debugging. Helpful exception tools.
  23. DEVELOPMENT TOOLBAR Halos quick, pretty source access class browser object

    inspector CSS browser live edit! Profiler built in Memory view built in
  24. WHY DIDN’T IT CATCH ON History seems to say it

    was close Then Rails came Seaside attacks some difficult web dev problems Rails simplified the tedious and mundane