Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My favorite is "goto Considered Harmful".

Yes, it can be abused, but can so nearly every other programming construct. There are places where goto makes sense, such as error handling or breaking out of nested loops. I hate seeing a Boolean flag(s) being tracked for whether or not break out of nested loops. It's more typing and confuses the intent. Just goto the label following the nested loop.

Also, nearly any looping construct can be implented using a conditional goto, and if you go down to assembly, they almost universally are. Jumps are goto's by another name. I've seen exceptions used for control flow. Awful. It's about knowing the appropriate construct for the problem at hand.

I've seen do{...}while(false) used with conditional breaks to avoid use of goto in error handling and it's confusing as you're reading through an unfamiliar codebase to see abuse like that. As I'm reading through the code, I see the 'do' and I expect the code to loop, only to continue reading and find out it doesn't loop. Frustrating.



Dijkstra was arguing in favor of structured programming languages powerful enough that you didn't need GOTO. For example you mostly see GOTO for error handling in C, because C lacks a structured way for resource cleanup.

Dijkstra certainly wasn't arguing you should use trick like do{...}while(false) to avoid using the GOTO keyword.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: