Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion GOTO considered harmful (was procmail sucks (was Re: The shooter is back))
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Linus Torvalds  
View profile  
 More options Feb 17 1998, 3:00 am
Newsgroups: comp.os.linux.development.system
From: torva...@transmeta.com (Linus Torvalds)
Date: 1998/02/17
Subject: Re: GOTO considered harmful (was procmail sucks (was Re: The shooter is back))

In article <6cao79$...@epic7.Stanford.EDU>,

Ian Burrell <iburr...@leland.Stanford.EDU> wrote:

>However, there is a big difference betweens nicely structured
>constructs and the code the formed by arbitrary use of branches and
>jumps.  For example, jumping into the middle of a loop produces an
>irreducible flow graph that needs to be removed before it can be
>analyzed.  This is what increases the code size and gives the compiler
>trouble.  Such problems can't be produced with well-structured code.

It can easily be done without goto's, using only "structured
constructs". Admittedly nobody calls this well-structured code ;)

        i = 1;
        switch (-1) {
                do {
                        printf("i=%d\n", i);
        case -1:
                        printf("i=%d\n", i);
                } while (++i < 10);
        }

The point being that you can mess up source code multiple ways, and
goto's aren't the worst of your problems.

Yes, goto's can result in worse code.  But goto's can result in better
code too, so what's the point here?

The fact is that bad programmers generate bad code, regardless of
whether they use goto's or not. Blaming bad code on goto's is silly,
it's a tool like any other, and can be mis-used like any other.

You can create a better _simple_ compiler if your language does not have
goto's (and doesn't allow the ugly case construct above that C allows).
But any compiler worth anything at all can handle goto's as well as
anything else, and if it makes the source code better structured then it
often makes the compiler generate better code too.

Goto's are often very useful for error cases, or odd cases that aren't
structured and where structured constructs only result in strange on
non-obvious code. These cases may not be common, but they are no less
valid for all that..

So people, please don't vilify the poor goto, nor make it anything more
than it is. It's a supremely useful construct in some cases, and a
language without it is a poorer language.

                Linus


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.