Category:Smalltalk: Difference between revisions

Line 509:
 
In both cases, you'd end up with a system infected with many Rosetta methods, which you'd have to remove afterwards (using "undo" or "delete"). And because Smalltalk keeps track of your changes, it usually involves additional cleanup work in your change history.
With b) comes the additional trouble that fileIn formats are different (chunk file, vs. XML file, vs. Monticello, vs. GNU-ST etc.). So in which dialect's fileOut format should the example be presented to be most convenient?
<br>For example, for export/import, GNU-ST uses a ''private format'' (which has the advantage of not needing the chunk format's bangs and especially the ugly bang doubling inside code and the empty chunk at the end):
<lang smalltalk>Number extend [
my_factorial [
^ (self < 2) ifTrue:[1] ifFalse:[ self * (self-1) my_factorial]
]
]</lang>
however, it is incompatible and not supported by those which use the historical chunk format:
<lang smalltalk>!Number methodsFor:'math'!
my_factorial
^ (self < 2) ifTrue:[1] ifFalse:[ self * (self-1) my_factorial]
! !</lang>
 
So in which dialect's fileOut format should the example be presented to be most convenient?
Therefore, expression-like snippets work more or less in all dialects, and snippets are usually presented in a functional or expression style, which works outside any class. Typically these define a function (here called "block") and then call it.
 
 
Therefore, expression-like snippets work more or less in all dialects, and snippets are usually presented in a functional or expression style, which works outside any class. Typically these define a function (here called "block") and then call it.
Typically these define a function (here called "block") and then call it.
<br>For the above, this might look like:
<lang smalltalk>factorial := [:n |
Line 521 ⟶ 536:
 
The advantage is that this code can be simply selected as a whole and evaluated.
The disadvantage is that it might look somewhat non-Smalltalk-like to not have it in a class/method.
 
==Citations==
Anonymous user