3 ms·
> If you're used to Java or C++, this object-oriented code may look strange, especially since Smalltalk uses some strange characters. < It's Smalltalk-76 that
by igouy 9y ago
> If you're used to Java or C++, this object-oriented code may look strange, especially since Smalltalk uses some strange characters. <
It's Smalltalk-76 that uses some strange characters.
The version that made it out of the lab into the wide-world was Smalltalk-80.
edited With help from Paolo Bonzini, Smalltalk-80 syntax for that square root code would be something more qwerty-friendly like:
sqrt
| guess |
(self <= 0.0) ifTrue: [
(self = 0.0)
ifTrue: [^0.0]
ifFalse: [self error: 'sqrt invalid for x < 0.']
].
guess := self timesTwoPower: self exponent // -2.
5 timesRepeat: [guess := (self - (guess*guess)) / (guess*2.0) + guess].
^guess
"I Can Read C++ and Java But I Can’t Read Smalltalk" pdf
http://carfield.com.hk/document/languages/readingSmalltalk.pdf http://carfield.com.hk/document/languages/readingSmalltalk.p...
- uytuijhgj 9y agoFrom your link: Finally, let’s insist that the separators be part of the method name; i.e., let’s require that the name of the method be “rotate by: around:” and let’s get rid of the spaces to get “rotateby:around:” as the name and finally, let’s capitalize internal words just for readability to get “rotateBy:around:”. Then our example could be written rotateBy: a around: v //This is Smalltalk This is also what Objective-C / Apple does.
- igouy 9y ago> This is also what Objective-C / Apple does. Inspired by Smalltalk-80. See "A short history of Objective-C" https://medium.com/chmcore/a-short-history-of-objective-c-aff9d2bde8dd https://medium.com/chmcore/a-short-history-of-objective-c-af...
- bonzini 9y agoThe "instfield" line is halving the exponent. In Smalltalk-80 you could write it guess := self timesTwoPower: self exponent // -2. Also, "user notify:" would become "self error:". Modern Smalltalk actually has complete exception handling, so you could also define an exception class (for example ArgumentOutOfRange) and trap it.