Quote:
|
Originally Posted by KevinB
There really is no advantage to doing this. If you're worried about code readability, try splitting the actual code up into separate files like this:
Code:
if (autonomous_mode) {
#include "auton.c"
} else {
#include "manual.c"
}
|
What? #include statements are
pre-processor directives ... they are (quite necessarily) executed before compilation and definately before you upload the code to the robot. For conditional includes, you'd have to use the pre-processor directive #ifdef ... #endif -- but this isn't what you mean to do. Presumably, everytime you run the robot you'd want to execute *both* autonomous mode, and manual mode -- meaning you'd more than likely want both "auton.c" and "manual.c" to be included every time. Instead of #include "auton.c", perhaps you mean some sort of function call, where the function is defined in auton.c? *color me confused*
Quote:
|
there is also the fact that such could result in code duplication - you may use some of the same code for the Process_Data_from_Local as you would for autonomous.
|
That's not such a big concern, though. If something increases readability, or efficiency, or some other desirable thing, you very may well say "re-usability be damned." Reducing code duplication is good because it reduces your work, and reduces the amount of errors creeping up because of subtly different versions ... but it isn't necessarily bad (not that it is--or isn't-- justified here). Oh, and all I really wanted was an excuse to say this (sorry that I forget who it was that said it): For code to be re-usable, it first has to be usable
