Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why should we always avoid using goto in coding?

Status
Not open for further replies.

whn

Programmer
Oct 14, 2007
265
US
I have never used 'goto' in my perl implementation. but I have to admit that I can not explain why it so evil?

could someone explain it to me? Thank you.
 
The first paragraph of the documentation for goto gives a good enough reason. Simply put, it's not needed.

For other reasons, it breaks the flow of control of programs. But this is not a perl issue as much as it is a greater programming issue. There are plenty of books on the subject of programming style. Pick up a couple of you're curious.

- Miller
 
Goto is sloppy. The newer techniques tend to package data and algorithms together, compartmentalize it, which is good for a variety of reasons. They make things more portable, for one. Libraries would not be possible with goto, or at least the implementation wouldn't be nearly as clean. I started out with Atari basic (which only used goto to call functions), and it was a nightmare to track down a problem, even in small programs. I'm not sure how jumping in and out of blocks would effect things, but I'm sure it would make things more complicated.
Object orientation is one more step away from the problems that goto tends to cause.
 
In other words, unless you're doing assembly programming, it's an outdated feature.

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top