Yes but this is really really really really really basic stuff - if you have to think for more than a second on this type of construct maybe you should not be a programmer ??
From: [email protected] [mailto:[email protected]] On Behalf Of Tony Gravagno Sent: 02 March 2011 23:40 To: [email protected] Subject: Re: [U2] Is this worth rewriting? > From:David Wolverton > But back to the 'issue' I was raising, although in > this example it's moot - the generic statement was > that 'IF ... # ... THEN' is 'bad style' ?? I still > have missed why that should be considered 'wrong' or > 'bad'. > > If it's purely style, then that's OK too and > discussion over! Different horses for different > courses! But when someone tells me something is 'bad', > I want to know the reasons why so I can advance my > understanding. I think the objection is to this: IF A # B THEN FOO ELSE BAR It's that Not/Else thing that can bend the brain. I think most people prefer: IF A = B THEN FOO ... We know what it is, so do this. ELSE BAR ... do this if the value is unexpected. Sure, it's perfectly logical to say "If it's anything else than what we expect, do something". But that extra ELSE clause means "but if it IS what we expect..." - that's what makes it non-intuitive. I fret about such things all the time, thinking about that next poor guy (me?) who might have to read the code in a year. So in new code I'll even occasionally re-phrase as follows: IF A = B THEN ... do something that doesn't change values END IF A # B THEN ... END While sacrificing the elegance of END ELSE and a tiny bit of performance, the eye can immediately jump to the right segment of code. Of course that shouldn't be done where values change, with functions where A and B are computed, something else happens in their generation, etc. My rule of thumb is that if it's too complex or the intent is unreadable, then it's probably coded wrong. Never mind if it actually does the logical operation, we can assume that part is OK. ;) T _______________________________________________ U2-Users mailing list [email protected] http://listserver.u2ug.org/mailman/listinfo/u2-users _____ No virus found in this message. Checked by AVG - www.avg.com Version: 10.0.1204 / Virus Database: 1435/3477 - Release Date: 03/02/11 _______________________________________________ U2-Users mailing list [email protected] http://listserver.u2ug.org/mailman/listinfo/u2-users
