Toggle

alister alister.nospam.ware at ntlworld.com
Mon Oct 13 04:09:49 EDT 2014


On Mon, 13 Oct 2014 05:43:10 +1100, Chris Angelico wrote:

> On Mon, Oct 13, 2014 at 5:38 AM, Tony the Tiger <tony at tiger.invalid>
> wrote:
>>> colour = 'red' if colour == 'blue' else 'blue'
>>
>> I call that a subtle bug that most likely will jump up and bite your
>> behind when you least expect it.
> 
> More generally, I'd say that this is solving a (very) slightly different
> problem: it's providing a "toggle with default" feature,
> where the part after the else is the default. If you don't want a
> default, that's a bug. I've known times when that default makes life a
> lot easier, in which case it'd be a feature.
> 
> ChrisA

if the value of colour is being set by user input & an incorrect value 
can be set the the error is in not validating user input and more complex 
solutions are definitely req.

If the value is being set within the program itself and colour gets set 
to an incorrect value the bug lies elsewhere in the program.

this looks like a simple requirement to alternate the colour of a GUI 
element so it is unlikely that incorrect values will be set.

sometimes it is easy to get carried away & overcomplicate a simple task, 
I tend to follow the "KISS" principle wherever possible 



-- 
40 isn't old.  If you're a tree.



More information about the Python-list mailing list