From: Enric Lafont Date: 2002-11-04T07:08:27+09:00 Subject: Re: Thoughts on Ruby Albert Wagner wrote: >Yes, superficially, just looking at a piece of Smalltalk code, without >understanding what it means, a lot of people come away with the wrong idea: >"Smalltalk syntax is wierd and complicated". Actually, Smalltalk syntax is >absurdly simple: There are ONLY objects and messages. e.g. > >conventional language: > >if > codeExecutedIfBooleanIsTrue >else > code ExecutedIfBooleanIsFalse >end > >Smalltalk: > > > IfTrue: [ codeExecutedIfBooleanIsTrue] > IfFalse: [ codeExecutedIfBooleanIsFalse] > >This does indeed look strange and complicated until you realize that expression> is an object, that can be sent the message IfTrue: with a code >block as an argument that is evaluated by the boolean object if expression> evaluates to True. It is exactly the same syntax as: > > One of the really NICE things in Ruby is the implicit "object" when calling functions, this is what enables Ruby to rewrite the aBoolean ifTrue: [ true Closure] ifFalse: [false Closure] to if aBoolean then: [true Closure] else: [false Closure] in this case, "if" is an Object method that evaluates the boolean expresion. And yes, it does not fit with the Ruby sintax, but maybe some sintax sugar can correct it.... :-) >[boolean expression] # object is code block that answers a boolean > whileTrue: [ code here ] # whileTrue: [] is message sent to code block > >and: > >1 to: 6 do: [ :integer | code here ] # object is integer 1 > # to: 6 do: [ ] is message sent to integer 1 > >It is this consistency in pure languages that cause problems for people coming >from such languages to Ruby. The corrolary is people coming from simple >procedural languages (C) and hybrid languages (C++) who have trouble grasping >the almost pureness of Ruby. Ruby sits midway between canonical pure OOP >(Smalltalk) and procedural/hybrid languages. Whether you enter Ruby from the >left or right you are bound to be suprised. > > Yes, but in this cases, the sintax sugar can help a lot, because you will need to use in very few cases. Enric