Thread: Removal of gotos

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    What? What does that have to do with using `break' or `continue'? What do they have to do with `switch'? Are you making some indirect association? ('break' -> `goto' <- 'case acase:')

    [Edit]

    I've got it now. You asked that because of the common "rule" that every `case' block must end with a `break'. It is a stupid rule and has nothing to do with the standard.

    [/Edit]

    Whatever.

    If the situation is best illustrated by a `switch' statement, I naturally use a `switch' statement, but you'll have to explain how that necessitates `break' or `continue'. I've managed without them for some time.

    Actually, come to think on it, most of my code is "library level" where a `switch' statement wouldn't be allowed for mechanical reasons (For example, in template code where you'd have to use a different construct simple because the `case' labels must be integer like.) or design reasons. (The related values are not constant/literal expressions.) Considering that, I suppose it would be safe to say I don't use `switch' statements.

    Soma
    Last edited by phantomotap; 03-04-2010 at 12:57 AM.

  2. #2
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by phantomotap View Post
    O_o

    What? What does that have to do with using `break' or `continue'?
    Switch's have cases which use "break." That's all he meant.

    The main reason goto's are bad is because they produce spaghetti code. "break" and "continue" do not produce spaghetti code. They are quite uniform and generally not too hard to follow. Using a few here and there (such as for/while/if statements, switch case/break is perfectly fine) is fine (even using a small amount of goto's under certain circumstances has been argued, even though I've never encountered them).
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Switch's have cases which use "break." That's all he meant.
    I don't know why he said it, but the association is too strong in the minds of most programmers. I blame the bogus "rule".

    "`if' statements have cases which use "break"."

    Hear? The association sounds silly. One doesn't necessitate the other. If you want to use `break' fine, but don't assume you need to because of a rule or because that's the way you first "see" it.

    The main reason goto's are bad is because they produce spaghetti code.
    Except where they don't. I use `goto' (and its "big brothers": `setjmp'/`longjmp') in virtually every "library level" function in C. (I hate C.) I dare you to try your hand at solid and structured source cleaning up of a dozen resources in the face of a dozen exit points without using `goto' in C.

    "break" and "continue" do not produce spaghetti code.
    Except where they do. If you care to search the Dev-C++ forum you'll find anecdotal "proof". A user had argued the same statement with me and Clifford, another regular. The source he posted as proof was a horrible mess of nesting and fake control structures solving the "N-Queen" problem. If you find it you'll find the companion source written by Clifford.

    Source is written for people. (That's probably a quote.) Source is written by people. (Which is plainly obvious.) It is the programmers writing the source that are responsible for "spaghetti" code. Programming is great like that; you can write crap source in any language using any construct.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strlwr() and delimiter removal
    By kryptkat in forum C++ Programming
    Replies: 14
    Last Post: 12-29-2009, 10:53 AM
  2. GoTo's?
    By Neo1 in forum C++ Programming
    Replies: 4
    Last Post: 07-09-2007, 03:24 AM
  3. linux removal
    By MadCow257 in forum Tech Board
    Replies: 2
    Last Post: 03-24-2006, 09:48 AM
  4. Deleting object after list removal (C++ visual studio)
    By RancidWannaRiot in forum Windows Programming
    Replies: 2
    Last Post: 10-20-2005, 06:06 PM