CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 4 of 4 FirstFirst 1234
Results 46 to 53 of 53
  1. #46
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Is using goto a bad practice

    Using exceptions for that is evil.
    Not only is it perversing the system, but it's also likely to have incredibely bad performances. Ssomething like more than 200 microseconds for each throw statement... More for "zero overhead" exceptions.

    In C++ exceptions must never be thrown in the normal control flow of a program.
    There are enterprises who use tools to log every exception in a file and never release the application before zero exceptions are thrown in the normal control flow of the program.

    Gotos are evil. Ok. But perversions used to avoid gotos can be worst.
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

  2. #47
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: Is using goto a bad practice

    Quote Originally Posted by wildfrog
    In Javascript (ECMA Script 3. ed) you got break and continue statements just as in C/C++, but in addition you can add an optional label to the keyword:
    Code:
    continue [label];
    and
    Code:
    break [label];
    Code:
    outerloop:
    while (a)
    {
        while (b)
        {
            if (someCondition)
                break outerLoop;
        }
    }
    This seems like an attempt to avoid the use of goto and other messy code to break/continue nested loops. What do you anti-goto'ers out there think of such a construct?
    break can be implemented in terms of goto. And that is the kind of limitation that break suffers over goto and hence I feel the goto debate keeps popping up. This would be a nice feature and I have read discussions around something like that happening on clc++m.

  3. #48
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: Is using goto a bad practice

    I programmed in Fortran for 20 years, so I have a deep-rooted loathing for goto in all its forms, including break and continue. Gotos increase the time taken to understand and to maintain any piece of code. If I never see another one, it will be too soon.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  4. #49
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: Is using goto a bad practice

    Who ressurrected this one and a half year old thread? I'm sure we will see the goto statement being removed from the C++ standard sooner, than we will see this discussion reach a conclusion.
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

  5. #50
    Join Date
    Nov 2002
    Location
    Foggy California
    Posts
    1,245

    Re: Is using goto a bad practice

    Quote Originally Posted by artella
    Hi Kevin,

    The problem that you mentioned above can be very easily circumvented by defining a
    unique identifier (e.g. a class), and then throwing that.
    [/code]
    Wow, a unique class for every goto? That sounds much more maintainable than just using a goto! Then there's the argument about performance (which others have brought up).

    But you obviously missed the point I made earlier. If you are going to use goto-like capabilities, then use a goto! Don't simulate a goto with features that aren't designed to be gotos. You'll only confuse other people who have to maintain the application.

    - Kevin
    Kevin Hall

  6. #51
    Join Date
    Sep 2007
    Posts
    62

    Smile Re: Is using goto a bad practice

    Hi Kevin,

    Your point about having multiple classes is a very good one (in addition to "confusion factor" you mentioned and also time issue pointed out by SuperKoko). In the case of your gotos appearing in sequentially separated code, I think you should be able to recycle the same class. However in nested gotos, you could have some serious problems. For example if you have two gotos, and the inner goto refers to a point in the code appearing after the reference of the outer goto, then you couldn’t reuse the same class. So this “alternative” becomes, like you said, messier and messier.

    Thanks.

    Hi Treus,

    I’m afraid I resurrected it. I thought that taking refuge in an old query would be the best way for me to ask a question on such an overdiscussed topic. It wont happen again
    Last edited by artella; September 26th, 2007 at 02:38 PM.

  7. #52
    Join Date
    Nov 2002
    Location
    Foggy California
    Posts
    1,245

    Re: Is using goto a bad practice

    Quote Originally Posted by artella
    Hi Treus,

    I’m afraid I resurrected it. I thought that taking refuge in an old query would be the best way for me to ask a question on such an overdiscussed topic. It wont happen again
    Personally, I'd rather resurrect an old thread rather than starting a whole new one. At least all the history is in the same place then. But that is just my humble opinion....

    (Of course it would be best to see if the answer already existed in the thread before resurrecting it.)

    - Kevin
    Kevin Hall

  8. #53
    Join Date
    Nov 2006
    Posts
    1,611

    Re: Is using goto a bad practice

    Gotos are fundamental to computers really so theres no avoiding them completely. I mean its translated to assembly with labels and jumps anyways.
    I think 'goto' was included in the spirit of C's position as an assembler (in it's original inception) - the unconditional jump was probably a significant portion of the assembler the original designers of C were intending to support.

    In the last 20 years of my own work, I've not had one reason to use goto (with a caveat I visit below), covering diverse topics that range from business applications to 3D simulations. Branchpoints, conditional and otherwise, are implied by other graceful constructs, like the close brackets and the return from a function.

    I think the notion of goto should be considered more in the light of what you're attempting to 'instruct' the computer to do. The more information you can include in your expression, the better the optimizer is able to do it's work. An unconditional branch doesn't carry with it much information, and may actually obviate the compiler's ability to restructure your code depending on context.

    The only exception where I have used goto is when I've mixed assembler and C++/C - in which case one could argue that I was using a C construct in place of an assembler counterpoint, and therefore not actually writing in C/C++.
    If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).

Page 4 of 4 FirstFirst 1234

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured