[Pharo-project] some patterns I would like to **kill**

Schwab,Wilhelm K bschwab at anest.ufl.edu
Fri Oct 22 17:13:57 EDT 2010


Stef,

#respondsTo: - no argument.  More defensive programming (aka masked bugs).  Tests like this have their place, but are over-used in Squeak.

Using #submorphs *might* be easier to defend.  Morphs were designed to be usable in large numbers, and one might argue (playing Devil's Advocate here) that lookups are cheaper than the additional gc load.  An instance variable could also cache stale information.  Of course, for something that is accessed frequently, an instance variable avoids the lookup and I agree that it is cleaner and easier to read.

Bill



________________________________________
From: pharo-project-bounces at lists.gforge.inria.fr [pharo-project-bounces at lists.gforge.inria.fr] On Behalf Of stephane ducasse [stephane.ducasse at free.fr]
Sent: Thursday, October 21, 2010 4:47 PM
To: Pharo Development
Subject: [Pharo-project] some patterns I would like to **kill**

Hi

I was reading Pluggable and friends
I identified some patterns.


The respondsTo plague
Examples:

color := self fillStyle asColor.
        (self labelMorph respondsTo: #enabled:)
                ifTrue: [self labelMorph enabled: self enabled].
        (self labelMorph respondsTo: #interactionState:)
                ifTrue: [self labelMorph interactionState: self interactionState]

(self labelMorph respondsTo: #enabled:) ifTrue: [
        self labelMorph enabled: aBoolean].

(self enabled not and: [self label isMorph and: [(self label respondsTo: #enabled:) not]])


by construction a labelObject should be a morph and it should answer enabled: and the case where this is not the case should be fixed.


Using submorphs to avoid one single inst var makes code quite ugly to read:


labelMorph
        "Answer the actual label morph."

        self hasSubmorphs ifFalse: [^nil].
        self firstSubmorph hasSubmorphs ifFalse: [^nil].
        ^self firstSubmorph firstSubmorph





_______________________________________________
Pharo-project mailing list
Pharo-project at lists.gforge.inria.fr
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project




More information about the Pharo-dev mailing list