Electronics > Microcontrollers

Pausing a Arduino shetch, and wait for a button press

<< < (3/3)

Bored@Work:

--- Quote from: alm on November 15, 2011, 05:42:19 pm ---Goto statements also make it hard to guarantee proper cleanup, like free()ing memory.
--- End quote ---

However, ironically the only idiom where goto is acceptable in the view of most professionals is a certain cleanup idiom to avoid code duplication while providing a controlled cleanup.


--- Quote ---Because of this issues, anyone who has to ask should avoid its use.
--- End quote ---

Indeed. Basic programming craftsmanship is to not use goto. Once you have mastered the craft you can start to occasionally break the rule if absolutely needed.

baljemmett:

--- Quote from: alm on November 15, 2011, 05:42:19 pm ---The debugging and maintenance argument is a valid one, however.

--- End quote ---

Yes, indeed; sorry, didn't mean to imply that it wasn't -- should have trimmed that quote a bit tighter.  Basically, using goto willy-nilly will make the poor sod who has to maintain your code later hate you, and that's not a good thing -- especially when the poor sod might be you once you've forgotten all about how the code you've just written works.

Mechatrommer:
if you can maintain locality in your code with goto statement, i think debugging hazard is not so serious. the fact is.. "for", "while" and those fancy loop statement is nothing else but just a "goto" translation in asm, with controlled and "encapsulated" locality. the problem is, kids usually made a far jump from another side of the world (between subroutines or between two very different purpose of code chunks, hence destroying locality and making debug almost imcomprehensible, certainly not the way to go. so "the advisor" will always pick the "safe side", hence promoting "not to use goto".

well, about the improper memory freeing and proper cleanup? "return" can do the same nasty thing, experience will tell. people who has to ask is afraid if he missed something he never heard ;)

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod