Originally Posted by
Darwin Froese
Awesome, thanks jim! My dad (who has no programming experience unfortunately. He just supports me A LOT) and I looked at someone's guide on youtube on how to program a robot and his was really cheap and moved according to "sunlight bounding boxes" i believe.
One other question I just came upon. Ever since I was taught programming I have been told to comment everything. But upon recently I read some advice in another programming book that told me to comment things that I was uncertain about, things that might be confusing to another person or things I want to do next time I open my code. I also read in a different book that the only comment lines someone puts in is the overview of the script at the top of the file. My question is, do I really need more comment lines than that.
Just figure I'd through in that question real quick.
Think about it this way... You've written a fairly complex bit of code, but it's been 5 years since you looked at it... Are you still going to be able to follow it and remember what you did? ... Comment anything that is not painfully obvious!
Like this...
Code:
// replace a command line flag, remove if NewFlag = NULL
VOID DoReplace(PTCHAR Str, PTCHAR OldFlag, PTCHAR NewFlag)
{ PTCHAR ft,fs; // pointers for string manip
// locate the old flag
ft = wcsstr(Str,OldFlag);
if (!ft)
return;
fs = ft;
// find end of flag
while((*fs != _T(' ')) && (*fs != 0))
fs++;
// finds start of next flag
while((*fs != _T('-')) && (*fs != 0))
fs++;
// copy line forward
while(*ft++ = *fs++);
// clean trailing spaces
ft = Str + lstrlen(Str) - 1;
while(*ft == _T(' '))
*ft-- = 0;
// add new flag
if (lstrlen(NewFlag))
{ lstrcat(Str,_T(" "));
lstrcat(Str,NewFlag); } }