[ENH] A Simpler Flasher (was: Re: [FIX] flasherMorphCleaned)

Scott Wallace scott.wallace at squeakland.org
Wed Apr 17 23:02:34 UTC 2002

Hi, Stephane,

I offer (attached, and also pasted in-line below for easy examination) a much smaller (total of four methods) and simpler Flasher as a replacement for FlasherMorph.

If one is to use a class as a learning tool, it should not be full of strange and puzzling things raise needless questions and set bad examples, and every method should earn its keep.  Our existing FlasherMorph has "just a few" deficiencies:

*  There's the initialization awkwardness you mention (but see the PS below regarding your fileout.)

*  It has dead code, #fullPrintOn:, that is never reached and should have long since have been winnowed out, and other code, #canHaveFillStyles, whose appearance in such a small class is at best puzzling to the beginner.

*  It lacks class comment, method comments, and method categories.

*  Its #step method calls "super color:", not generally a commendable practice (i.e. invoking super to a selector different from the caller's own selector,) for beginners.

The replacement Flasher has none of the above deficiencies.

  -- Scott

PS Stephane:  Regarding your suggested change to the existing FlasherMorph, there was actually a flaw in it, which you will see if you evaluate "PartsBin initialize" (to clear out the thumbnail cache -- something that occasionally needs to be done) and then launch a fresh Objects tool, and look at the Flasher there -- it will be, wrongly, yellow.  This is because EllipseMorph's initializeToStandAlone sets yellow as its color.  That's the reason FlasherMorph's initializeToStandAlone needed to set the color to the desired red *after* calling super.  You don't see this effect in a running instance, because the step method is continuously setting the color afresh, but the issue shows up when launching an instance solely for the purpose of obtaining a thumbnail, in which case the instance is not "stepped".  Check out the attached new Flasher's simplified way of dealing with this.


'From Squeak3.3alpha of 18 January 2002 [latest update: #4827] on 17 April 2002 at 12:28:55 pm'!
"Change Set:		simplerFlasher-sw
Date:			17 April 2002
Author:			Scott Wallace

A simpler and cleaner flasher"!

EllipseMorph subclass: #Flasher
	instanceVariableNames: 'onColor '
	classVariableNames: ''
	module: #(Squeak Morphic Demo)!

!Flasher commentStamp: 'sw 4/17/2002 12:04' prior: 0!
A simple example - a circle that flashes.

The "onColor" instance variable indicates the color to use when "on",  A darker color is used to represent "off".

The #step method, called every 500ms. by default, alternatively makes the flasher show its "on" and its "off" color.!

!Flasher methodsFor: 'initialization' stamp: 'sw 4/17/2002 12:11'!
	"Initialize the flasher."

	super initializeToStandAlone.
	color _ onColor _ Color red.
	self borderWidth: 2.
	self extent: 25 at 25! !

!Flasher methodsFor: 'stepping' stamp: 'sw 4/17/2002 12:07'!
	"Perform my standard periodic action"

	super step.
	color = onColor
		ifTrue: [self color: (onColor alphaMixed: 0.5 with: Color black)]
		ifFalse: [self color: onColor]! !

!Flasher methodsFor: 'stepping' stamp: 'sw 4/17/2002 12:05'!
	"Answer the desired time between steps, in milliseconds."

	^ 500! !

!Flasher class methodsFor: 'parts bin' stamp: 'sw 4/17/2002 11:37'!
	"Answer a description of the receiver for use in a parts bin"

	^ self partName:	'Flasher'
		categories:		#('Demo')
		documentation:	'A circle that flashes'! !


At 11:22 AM +0200 4/17/02, ducasse at iam.unibe.ch wrote:
>from preamble:
>"Change Set:		flasherMorphCleaned
>Date:			17 April 2002
>Author:			stephane ducasse
>clean the initialize and initializeToStandalone
>method. the code of initialize was called two times and may be more.
>Can somebody check this because I do not know how to validate the
>This class is important because this is a simple one that newbies can
>start to look at to understand Squeak and OO

-------------- next part --------------
Skipped content of type multipart/appledouble

More information about the Squeak-dev mailing list