![]() Instead of the following– byte n = Serial.available() Ĭhar c = Serial.read() //read and discard What is about this one: while(Serial.available() & Serial.read()) Write your code with an eye on the limits of human attention and short-term memory. It's really hard to follow program logic if your nesting is more than 3 or 4 levels deep. That way you can hide some of the complexity behind the function name instead of having to scroll over it every time you're in that section. Instead of just throwing all your raw code together, the best way to simplify complex conditions is to pull some subconditions out into functions. The last time I had to fix something in there it took about 50 times longer to find what I needed to change than to make the change itself, then several rounds of testing just to make sure I didn't break some other case that was supposed to follow a different path through the branches. ![]() I prefer to call if the "13 Levels of Hell". It's nested 13 levels in at the deepest part, and is not-very-affectionately called the "Baker's Dozen" by the previous people that have worked on it. ![]() One script I maintain at my work has a beast of if-elses and for loops at the end to determine if the overall result of all the work the script did counts as a pass or fail. I recently created a program that uses several deeply nested if/else statements.
0 Comments
Leave a Reply. |