Well I'm working on some pseudo-code.... Personally I really like switch/case statements, but unfortunately they are not available in all languages, plus they aren't always useful for overlapping conditions. So for this instance, I have a series of '<' '>' conditions that overlap. I can easily just do it with a series of 'IF' statements and not use any 'ELSE' statements, but that mean that you have to evaluated every IF every time ... so then there are nested IF statements. Nested statements are great, pretty much bread and butter of programming, but especially IF statements, they tend to become hard to read after awhile.
if condition1:
...
if condition2:
...
else:
...
else:
...
that is pretty straight forward, but in my case I have:
if condition1:
...
if condition2:
...
if conditio3:
...
if condition4:
...
else if condition5:
...
if condition6:
...
else if condition7:
...
if condition8:
.......
you see where this is going.... even with proper indenting, this can be hard to read, and without, no hope. Comments help, but should code ever be that complicated? So when is nesting to much? what are other options? But then again is the efficiency of the checks more important? Many questions that we all must deal with when writing code.
No comments:
Post a Comment