Unused ugly morph methods...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Unused ugly morph methods...

stepharo
I really hope that Bloc will forbid such systematic submorphs use
because it leads to code like that.

Stef


submorphNamed: aName
     ^ self submorphNamed: aName ifNone: [nil]

submorphNamed: aName ifNone: aBlock
     "Find the first submorph with this name, or a button with an action
selector of that name"


     self submorphs do:
             [:button | | sub args |
             (button respondsTo: #actionSelector)
                 ifTrue: [button actionSelector == aName ifTrue: [^button]].
             ((button respondsTo: #arguments) and: [(args := button
arguments) notNil])
                 ifTrue: [(args at: 2 ifAbsent: [nil]) == aName ifTrue:
[^button]].
             (button isAlignmentMorph)
                 ifTrue: [(sub := button submorphNamed: aName ifNone:
[nil]) ifNotNil: [^sub]]].
     ^aBlock value

Reply | Threaded
Open this post in threaded view
|

Re: Unused ugly morph methods...

Aliaksei Syrel

It is forbidden by contract :) 100%

On Jan 31, 2016 9:31 PM, "stepharo" <[hidden email]> wrote:
I really hope that Bloc will forbid such systematic submorphs use because it leads to code like that.

Stef


submorphNamed: aName
    ^ self submorphNamed: aName ifNone: [nil]

submorphNamed: aName ifNone: aBlock
    "Find the first submorph with this name, or a button with an action selector of that name"


    self submorphs do:
            [:button | | sub args |
            (button respondsTo: #actionSelector)
                ifTrue: [button actionSelector == aName ifTrue: [^button]].
            ((button respondsTo: #arguments) and: [(args := button arguments) notNil])
                ifTrue: [(args at: 2 ifAbsent: [nil]) == aName ifTrue: [^button]].
            (button isAlignmentMorph)
                ifTrue: [(sub := button submorphNamed: aName ifNone: [nil]) ifNotNil: [^sub]]].
    ^aBlock value

Reply | Threaded
Open this post in threaded view
|

Re: Unused ugly morph methods...

stepharo

It is forbidden by contract :) 100%

I like that
What would be great is that we can create QA rules dedicated to Bloc and Brick.



On Jan 31, 2016 9:31 PM, "stepharo" <[hidden email]> wrote:
I really hope that Bloc will forbid such systematic submorphs use because it leads to code like that.

Stef


submorphNamed: aName
    ^ self submorphNamed: aName ifNone: [nil]

submorphNamed: aName ifNone: aBlock
    "Find the first submorph with this name, or a button with an action selector of that name"


    self submorphs do:
            [:button | | sub args |
            (button respondsTo: #actionSelector)
                ifTrue: [button actionSelector == aName ifTrue: [^button]].
            ((button respondsTo: #arguments) and: [(args := button arguments) notNil])
                ifTrue: [(args at: 2 ifAbsent: [nil]) == aName ifTrue: [^button]].
            (button isAlignmentMorph)
                ifTrue: [(sub := button submorphNamed: aName ifNone: [nil]) ifNotNil: [^sub]]].
    ^aBlock value