Organization: University of Windsor, Ontario, Canada
Lines: 30
I have noticed this discussion about the use of break, continue, goto, etc. in C/C++ programming. I must say that I actually *prefer* to use structured programming techniques, especially in complicated code. My reasons for this are simple... Whenever I write a program for someone else or myself, I, of course, wrote it to do the desired task. Once, I finished it, I archived it and left it sit somewhere on some floppy disk until it was needed again. Now, if I did not adhere to structured programming conventi
ons, I would not even remember how exactly I used my returns, breaks, continues, and gotos and therefore, I could get myself into some trouble adding code to a program; i.e. a function with more than 1 return statement and adding code to it after the first return statement which should have been added also before every return statement. Surely, a function such as:
int g(int a, int b) {
if (a < b)
return 1;
else
return 0;
}
is trivial but I think it is a much better practice to use:
int g(int a, int b) {
return (a < b) ? 1 : 0;
}
since, you now are treating the function g as a function that has a place of entry and a place of exit. This makes code very clean especially in complicated functions and in simple/complicated long functions. If I did not adhere to such practices then I would have difficulty adding new code or modifying old code in my *own* program, let alone anyone else's.
I feel that people should be consistent in programming... very consistent especially if the program is going to sit for a period of time when nobody is going to be modifying it. Conforming to structured practices allows one to more conclusively *prove* his/her program correct since there is ONLY 1 RETURN statement in the function and ALL of the code leads to that *CONCLUSION* or return statement. Thus, I could much more easily say that the second function of g() is correct than that of the first one where
I would have to check each and every return statement and all paths that lead to it. God help you if you have nested loops, if/else's and switch's in one function! :-)
Now, I have not been programming too long, since grade 9 and now I am in 2nd year university, BUT that does not mean in any way that I do not know what I am doing in C, C++, PostScript, NeWS, FORTRAN, BASIC, 80x86 Assembler, etc. BUT I HATE messy programming (for even which I am at fault) because it is very hard to "come bcak to" after a long time and it is also hard to catch those small weenie-little bugs that cause your program to not work properly.