The death of GOTO (user search)
       |           

Welcome, Guest. Please login or register.
Did you miss your activation email?
May 01, 2024, 10:23:55 AM
News: Election Simulator 2.0 Released. Senate/Gubernatorial maps, proportional electoral votes, and more - Read more

  Talk Elections
  General Discussion
  History (Moderator: Southern Senator North Carolina Yankee)
  The death of GOTO (search mode)
Pages: [1]
Author Topic: The death of GOTO  (Read 1950 times)
Gabu
Atlas Star
*****
Posts: 28,386
Canada


Political Matrix
E: -4.32, S: -6.52

« on: January 31, 2005, 10:54:26 PM »

Looking at the dates on those pieces of writing, I think we can safely say that their predictions of doom and destruction fortunately did not come true.
Logged
Gabu
Atlas Star
*****
Posts: 28,386
Canada


Political Matrix
E: -4.32, S: -6.52

« Reply #1 on: February 01, 2005, 02:03:44 PM »

Even now, most acceptable uses of GOTOs could be transformed into structured programming, if the appropriate structure were available.  However, these structures are numerous and individually of little use, it doesn't make sense to code them just to get rid of the humble GOTO.

What muon2 was talking about is that it's impossible to remove the "goto" type of statement entirely, because anything that disrupts the linear execution of commands must use some sort of "goto" statement.  There are no "while", "for", etc. loops, nor are there "if/else" statements, in machine language, which is what all programs eventually become.  There's only the "goto" sort of command.  Loops, branching statements, etc. in high-level languages like C++ and Java are all simply abstractions that make you unable to royally screw up your program flow through the misuse of "goto" statements.   They all get translated into "goto" commands that are executed if a certain condition is true when you compile your program into machine language.  So, in this way, it is true that full elimination of the "goto" statement is simply impossible.

However, that does not mean that the explicit call of a "goto" statement in a high-level language should be allowed.  I'm personally of the school of thought that it shouldn't be.  While it's true that you can get some marginal benefit in speed if you use it, the danger is way, way too large unless you know exactly what you're doing when you do it, and even then, it makes code very unreadable to have no indentations or anything to set the contents of a loop or a branch statement aside from surrounding code, especially if you have multiple nested types of these statements.
Logged
Gabu
Atlas Star
*****
Posts: 28,386
Canada


Political Matrix
E: -4.32, S: -6.52

« Reply #2 on: February 01, 2005, 10:54:43 PM »

Experience watching those around me makes me tend to support your argument. And for most applications it makes sense.

However, I've been programming since 1969, and the GOTO statement was mandatory back then. I was exposed to flowcharts (with branches equivalent to the GOTO) since 1964 and played with them before I had access to programming. From my exposure to branch statements early on, I have no problem reading linear code. This has been a great boon when I've had to write real-time data acquisition code, device drivers, and direct machine code.

When I teach advanced electronics I always include a discussion of the branch in digital machines. I find that knowing what really goes on in the computer is a great aid in understanding problems that may arise in actual use.

Well, yes, it's not impossible to read code that uses a "goto" statement instead of an abstract type of loop or branching statement; it's just more difficult.  Plus, there really is no real reason to have explicit uses of "goto" in code anymore unless you need to really, really optimize something to absolute death.
Logged
Gabu
Atlas Star
*****
Posts: 28,386
Canada


Political Matrix
E: -4.32, S: -6.52

« Reply #3 on: February 02, 2005, 03:28:08 AM »
« Edited: February 02, 2005, 03:35:57 AM by Senator Gabu, PPT »

My first exposure to programming was BASIC, and I sort of missed the Goto when i was first started looking at C++.  And, in a way, it can make the programming simpler for some sorts of programs.  But I can definitely see the problems with it, and don't miss it anymore, especially now that I know how to use OOP.  It may be a bit slower, but the less obfuscation the better imo, even at the expense of some speed.

Yes; without the goto statement, you can't do something like this:

#include <stdio.h>

void function1(void)
{
  printf("I feel so rejected.\n");

label2:
  goto label3;
}

void function2(void) { goto label1; }

void function3(void)
{
label1:
  goto label2;
}

int main(int argc, char *argv[])
{
label3:
  printf("PLEASE GOD MAKE IT STOP\n");

  function2();

  return 0;
}


I'm just about ready to gouge my eyeballs out and I'm the guy who wrote that.
Logged
Pages: [1]  
Jump to:  


Login with username, password and session length

Terms of Service - DMCA Agent and Policy - Privacy Policy and Cookies

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Page created in 0.03 seconds with 12 queries.