widgetDo: vs ifWidget:

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

widgetDo: vs ifWidget:

Peter Uhnak
Hi,

in Spec Adapter there's method

widgetDo: aBlock
^ self widget ifNotNil: aBlock


my question however is:
does the naming make sense?

#*Do: is generally associated with iterating over collections. Widget is always a single entity.
On the other hand we have #ifNil: #ifTrue: #ifFalse:

There is also #ifNotNilDo:, however that is superseded by #ifNotNil:

So from this perspective, wouldn't it make more sense to have this?
ifWidget: aBlock
    ^ self widget ifNotNil: aBlock

What do you think?

Thanks,
Peter
Reply | Threaded
Open this post in threaded view
|

Re: widgetDo: vs ifWidget:

Aliaksei Syrel
The same naming blablaDo: is heavily used in Bloc and therefore in Brick. I personally like blablaDo: more, because it hides check logic from user and doesn't force to think about if-elses. It's all about "if" word. You know, when reader sees "if" a complexity of an app instantly rises (in the head).

But let's discuss :) I agree that it can be associated with iteration and is not the best idea...

Cheers,
Alex

On Wed, Sep 2, 2015 at 10:56 AM, Peter Uhnák <[hidden email]> wrote:
Hi,

in Spec Adapter there's method

widgetDo: aBlock
^ self widget ifNotNil: aBlock


my question however is:
does the naming make sense?

#*Do: is generally associated with iterating over collections. Widget is always a single entity.
On the other hand we have #ifNil: #ifTrue: #ifFalse:

There is also #ifNotNilDo:, however that is superseded by #ifNotNil:

So from this perspective, wouldn't it make more sense to have this?
ifWidget: aBlock
    ^ self widget ifNotNil: aBlock

What do you think?

Thanks,
Peter

Reply | Threaded
Open this post in threaded view
|

Re: widgetDo: vs ifWidget:

stepharo
In reply to this post by Peter Uhnak


Le 2/9/15 10:56, Peter Uhnák a écrit :
Hi,

in Spec Adapter there's method

widgetDo: aBlock
^ self widget ifNotNil: aBlock


my question however is:
does the naming make sense?

Not even the naming. I would say. lot of code in spec should be rewritten. The holder should be most of the time directly exposed to reduce the API.


#*Do: is generally associated with iterating over collections. Widget is always a single entity.
On the other hand we have #ifNil: #ifTrue: #ifFalse:

There is also #ifNotNilDo:, however that is superseded by #ifNotNil:

So from this perspective, wouldn't it make more sense to have this?
ifWidget: aBlock
    ^ self widget ifNotNil: aBlock

What do you think?

Thanks,
Peter

Reply | Threaded
Open this post in threaded view
|

Re: widgetDo: vs ifWidget:

stepharo
In reply to this post by Peter Uhnak


Le 2/9/15 10:56, Peter Uhnák a écrit :
Hi,

in Spec Adapter there's method

widgetDo: aBlock
^ self widget ifNotNil: aBlock


my question however is:
does the naming make sense?

#*Do: is generally associated with iterating over collections. Widget is always a single entity.
On the other hand we have #ifNil: #ifTrue: #ifFalse:

There is also #ifNotNilDo:, however that is superseded by #ifNotNil:

So from this perspective, wouldn't it make more sense to have this?
ifWidget: aBlock
    ^ self widget ifNotNil: aBlock


I prefer widgetDo:
because this if logic is not really good and the user should not be exposed

What do you think?

Thanks,
Peter

Reply | Threaded
Open this post in threaded view
|

Re: widgetDo: vs ifWidget:

Peter Uhnak
In that case I rest my case and I will stick with #widgetDo: :)


Not even the naming. I would say. lot of code in spec should be rewritten. The holder should be most of the time directly exposed to reduce the API.
 
I know; it is moving, albeit slowly.

Thanks,
Peter