Re: More elegance than a long if/else
Re: More elegance than a long if/else
- Subject: Re: More elegance than a long if/else
- From: Quincey Morris <email@hidden>
- Date: Sat, 11 Mar 2017 11:45:57 -0800
On Mar 11, 2017, at 06:30 , Pascal Bourguignon <email@hidden> wrote:
>
> My argument is that algebraic expressions are clearer than switches.
And it’s a *convincing* argument when you switch to a purely arithmetic problem (such as: how to add two numbers).
Seriously, though, I apologize if I let anyone think I failed to see the argument for — the advantages of — a concise numerical expression. Someone (Jeff) had already given that part of the answer. Yet there may well be multiple answers for which there is a valid argument.
Finally, before stepping out of this thread permanently, I’ll point out that although Jeff knew the (or, a) right answer, he inadvertently used the wrong operator. On top of that, there was a second correction to handle the edge case at upper end of the range, and the lower end edge case (if the battery level value is negative) still isn’t handled as the original code would. Finding an arithmetic solution to a logical problem is a non-trivial exercise, and “it can be argued that” for a reader of the code, decoding the resulting non-trivial arithmetic expression carries a non-trivial conceptual load.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden