[Cuis-dev] Interesting thoughts about Color

Juan Vuletich juan at jvuletich.org
Sun Apr 28 15:48:29 PDT 2019


Hi Phil,

On 4/28/2019 2:20 PM, Phil B via Cuis-dev wrote:
> I was reading a thread going on over on pharo-dev about Color and 
> thought it was apropos for us.  Many of the more commonly used 
> instance methods (#lighter, #darker, #alpha: etc.) are named as if 
> they were accessors or actions which would most naturally be assumed 
> to modify the current color but actually create a new color.  If you 
> work with Color to any extent the current behavior is accepted as 
> normal since it is quasi-immutable, but this naming/behavior impedance 
> mismatch does seem pretty obvious when you think about it.  Perhaps we 
> should think about modifying these method names to better reflect what 
> they are actually doing? (and perhaps make Color more explicitly 
> immutable?)

I think that `Color red darker` makes perfect sense. No one should think 
that it takes "red" and turns "all red" into "dark red". It should be 
understood as 'just something like red, but darker'.

#alpha: is wrong, because it really looks like a setter, but Colors are 
(at least conceptually) immutable. You can not turn red into something 
else, in the same way you can not turn 7 into something else. #alpha: 
should be renamed #withAlpha:, so you can write `Color red withAlpha: 
0.5` that does make sense. Same with #adjustBrightness: and 
#adjustSaturation:brightness:.

WRT making Color immutable... All methods that change state are marked 
as 'private'. What else do you suggest?

Thanks,

-- 
Juan Vuletich
www.cuis-smalltalk.org
https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
https://github.com/jvuletich
https://www.linkedin.com/in/juan-vuletich-75611b3
@JuanVuletich



More information about the Cuis-dev mailing list