I hate the "No GoTo" rule. GoTo is a perfectly valid programming concept. Look at assembly, the entire thing consists of GoTos. That isn't to say, the don't have their bad uses, but they can be very useful. For instance, if you want to just move on to the next element in a For or While loop, some languages support the "Continue" keyword. This is essentially a keyword that lets you "goto" the start of the loop. There's also things like "exit for" or "exit while" in some languages. Where this construct doesn't exist, a goto works quite well. The "break" in the switch-case statements is essentially a goto. Most of the time I don't use Gotos, because people think they are the worst thing ever, and that they should never be used, but they really do have some legitimate uses. Often restructuring the entire program flow just because you don't want to use a single goto, will create more bugs and confusion then using the goto would have in the first place.
I think that it's more of a comment of doing the "right thing" vs. doing "easy thing". Hacking something rather than taking the time to properly architect / re-architect it may give you short term speed, but I find that it costs more time and bugs. You should always do what you believe to be best.
I hate the "No GoTo" rule. GoTo is a perfectly valid programming concept. Look at assembly, the entire thing consists of GoTos. That isn't to say, the don't have their bad uses, but they can be very useful. For instance, if you want to just move on to the next element in a For or While loop, some languages support the "Continue" keyword. This is essentially a keyword that lets you "goto" the start of the loop. There's also things like "exit for" or "exit while" in some languages. Where this construct doesn't exist, a goto works quite well. The "break" in the switch-case statements is essentially a goto. Most of the time I don't use Gotos, because people think they are the worst thing ever, and that they should never be used, but they really do have some legitimate uses. Often restructuring the entire program flow just because you don't want to use a single goto, will create more bugs and confusion then using the goto would have in the first place.
ReplyDeleteI think that it's more of a comment of doing the "right thing" vs. doing "easy thing".
ReplyDeleteHacking something rather than taking the time to properly architect / re-architect it may give you short term speed, but I find that it costs more time and bugs.
You should always do what you believe to be best.
Something like that DOES happen!
ReplyDeleteIt's just that the person who gets eaten by the monster is the poor sod who has to maintain the code!-(