because when I see code like that, it makes me sick! I wonder also when we migrate to Athens if we will not rewrite all that anyway. fillRectangle: aRectangle basicFillStyle: aFillStyle "Fill the given rectangle with the given, non-composite, fill style." | pattern | (aFillStyle isKindOf: InfiniteForm) ifTrue: [ ^self infiniteFillRectangle: aRectangle fillStyle: aFillStyle ]. (aFillStyle isSolidFill) ifTrue:[^self fillRectangle: aRectangle color: aFillStyle asColor]. "We have a very special case for filling with infinite forms" (aFillStyle isBitmapFill and:[aFillStyle origin = (0@0)]) ifTrue:[ pattern := aFillStyle form. (aFillStyle direction = (pattern width @ 0) and:[aFillStyle normal = (0@pattern height)]) ifTrue:[ "Can use an InfiniteForm" ^self fillRectangle: aRectangle color: (InfiniteForm with: pattern)]. ]. "Use a BalloonCanvas instead" self balloonFillRectangle: aRectangle fillStyle: aFillStyle.
I always wondering how anybody can write such code with smalltalk 2014-06-26 0:43 GMT+04:00 stepharo <stepharo@free.fr>:
because when I see code like that, it makes me sick! I wonder also when we migrate to Athens if we will not rewrite all that anyway.
fillRectangle: aRectangle basicFillStyle: aFillStyle "Fill the given rectangle with the given, non-composite, fill style."
| pattern |
(aFillStyle isKindOf: InfiniteForm) ifTrue: [ ^self infiniteFillRectangle: aRectangle fillStyle: aFillStyle ].
(aFillStyle isSolidFill) ifTrue:[^self fillRectangle: aRectangle color: aFillStyle asColor].
"We have a very special case for filling with infinite forms" (aFillStyle isBitmapFill and:[aFillStyle origin = (0@0)]) ifTrue:[ pattern := aFillStyle form. (aFillStyle direction = (pattern width @ 0) and:[aFillStyle normal = (0@pattern height)]) ifTrue:[ "Can use an InfiniteForm" ^self fillRectangle: aRectangle color: (InfiniteForm with: pattern)]. ]. "Use a BalloonCanvas instead" self balloonFillRectangle: aRectangle fillStyle: aFillStyle.
Because Smalltalk lacks a "switch/case" control flow structure? :) Esteban A. Maringolo 2014-06-27 15:42 GMT-03:00 Denis Kudriashov <dionisiydk@gmail.com>:
I always wondering how anybody can write such code with smalltalk
2014-06-26 0:43 GMT+04:00 stepharo <stepharo@free.fr>:
because when I see code like that, it makes me sick! I wonder also when we migrate to Athens if we will not rewrite all that anyway.
fillRectangle: aRectangle basicFillStyle: aFillStyle "Fill the given rectangle with the given, non-composite, fill style."
| pattern |
(aFillStyle isKindOf: InfiniteForm) ifTrue: [ ^self infiniteFillRectangle: aRectangle fillStyle: aFillStyle ].
(aFillStyle isSolidFill) ifTrue:[^self fillRectangle: aRectangle color: aFillStyle asColor].
"We have a very special case for filling with infinite forms" (aFillStyle isBitmapFill and:[aFillStyle origin = (0@0)]) ifTrue:[ pattern := aFillStyle form. (aFillStyle direction = (pattern width @ 0) and:[aFillStyle normal = (0@pattern height)]) ifTrue:[ "Can use an InfiniteForm" ^self fillRectangle: aRectangle color: (InfiniteForm with: pattern)]. ]. "Use a BalloonCanvas instead" self balloonFillRectangle: aRectangle fillStyle: aFillStyle.
On Fri, Jun 27, 2014 at 11:58 AM, Esteban A. Maringolo <emaringolo@gmail.com
wrote:
Because Smalltalk lacks a "switch/case" control flow structure? :)
and of course it has one that works just fine. Esteban A. Maringolo
2014-06-27 15:42 GMT-03:00 Denis Kudriashov <dionisiydk@gmail.com>:
I always wondering how anybody can write such code with smalltalk
2014-06-26 0:43 GMT+04:00 stepharo <stepharo@free.fr>:
Steph, it begs for double-dispatching. So why shoot InfiniteForm instead of fixing the code/ It makes no sense to me. Double-dispatching is a pattern you know well. Apply it here.
because when I see code like that, it makes me sick! I wonder also when we migrate to Athens if we will not rewrite all that anyway.
fillRectangle: aRectangle basicFillStyle: aFillStyle "Fill the given rectangle with the given, non-composite, fill
style."
| pattern |
(aFillStyle isKindOf: InfiniteForm) ifTrue: [ ^self infiniteFillRectangle: aRectangle fillStyle: aFillStyle ].
(aFillStyle isSolidFill) ifTrue:[^self fillRectangle: aRectangle color: aFillStyle asColor].
"We have a very special case for filling with infinite forms" (aFillStyle isBitmapFill and:[aFillStyle origin = (0@0)]) ifTrue:[ pattern := aFillStyle form. (aFillStyle direction = (pattern width @ 0) and:[aFillStyle normal = (0@pattern height)]) ifTrue:[ "Can use an InfiniteForm" ^self fillRectangle: aRectangle color: (InfiniteForm
with:
pattern)]. ]. "Use a BalloonCanvas instead" self balloonFillRectangle: aRectangle fillStyle: aFillStyle.
-- best, Eliot
2014-06-27 16:31 GMT-03:00 Eliot Miranda <eliot.miranda@gmail.com>:
On Fri, Jun 27, 2014 at 11:58 AM, Esteban A. Maringolo <emaringolo@gmail.com> wrote:
Because Smalltalk lacks a "switch/case" control flow structure? :) and of course it has one that works just fine.
Really? Which one? Or are you referring to this code pattern? (a = 1) ifTrue: [^...]. (a = 2) ifTrue: [^...]. (a = 3) ifTrue: [^...]. Double dispatching is not always an option. :) Esteban A. Maringolo
he is referring to #caseOf: and #caseOf:otherwise: which are a bit controversial ;-) On 27 Jun 2014, at 21:38, Esteban A. Maringolo <emaringolo@gmail.com> wrote:
2014-06-27 16:31 GMT-03:00 Eliot Miranda <eliot.miranda@gmail.com>:
On Fri, Jun 27, 2014 at 11:58 AM, Esteban A. Maringolo <emaringolo@gmail.com> wrote:
Because Smalltalk lacks a "switch/case" control flow structure? :) and of course it has one that works just fine.
Really? Which one?
Or are you referring to this code pattern? (a = 1) ifTrue: [^...]. (a = 2) ifTrue: [^...]. (a = 3) ifTrue: [^...].
Double dispatching is not always an option. :)
Esteban A. Maringolo
On Fri, Jun 27, 2014 at 12:38 PM, Esteban A. Maringolo <emaringolo@gmail.com
wrote:
2014-06-27 16:31 GMT-03:00 Eliot Miranda <eliot.miranda@gmail.com>:
On Fri, Jun 27, 2014 at 11:58 AM, Esteban A. Maringolo <emaringolo@gmail.com> wrote:
Because Smalltalk lacks a "switch/case" control flow structure? :) and of course it has one that works just fine.
Really? Which one?
Or are you referring to this code pattern? (a = 1) ifTrue: [^...]. (a = 2) ifTrue: [^...]. (a = 3) ifTrue: [^...].
Double dispatching is not always an option. :)
And it doesn't work in this case? -- best, Eliot
participants (5)
-
Denis Kudriashov -
Eliot Miranda -
Esteban A. Maringolo -
stepharo -
Sven Van Caekenberghe