• gnasher729 (unregistered)

    In one large product I worked on, there was one goto statement. Instead of a trivial for-loop someone thought using "goto" would be quicker. We added a comment to please leave it there is an example of human stupidity.

  • Sauron (unregistered)

    Let's see the positive side: if ever the else keyword gets deprecated in the future, than at least they're prepared.

  • NoLand (unregistered)

    You can do better than this, really:

    if (condition) goto skipIt1;
    /* do else things */
    goto skipIt2;
    skipIt1:
    /* do if things /*
    skipIt2:
    /* continue */
    

    I mean, skipping was there before branching was even a thing, historically… ;-)

  • NoLand (unregistered)

    BTW, this should really be

    pre > code { overflow-x: auto; }
    

    instead of

    pre > code { overflow-x: scroll; }

    Just saying. (Traditional coda to any critical comment.)

  • Sole Purpose Of Visit (unregistered)

    In theory, you could get rid of this obnoxiousness by writing a simple parsing program (the goto token inside an if statement is a bit of a giveaway) and just substituting via a template.

    In practice, I wouldn't bother. It's obnoxious, but it works.

  • Anonymous') OR 1=1; DROP TABLE wtf; -- (unregistered)

    If this is C++ and their pseudo-else block contains any variable declarations with initializers or non-trivial constructors, they'd get a compiler error about the goto jumping past initialization too.

  • Sole Purpose Of Visit (unregistered) in reply to NoLand

    Not really true. Skipping is branching.

    However, writing high-level code as if it were assembler (skipping) seems to me to ignore the benefits of writing high-level code.

    (Leaving the dubious benefits of the common "single point of exit" pattern and the even more dubious benefits of a longjmp, of course.)

  • Conradus (unregistered)

    When you come to an else, you must skip it! Skip it good!

  • (nodebb) in reply to NoLand

    Well some of us still do it like that (at least when I'm using my home build 8-bit computer) :-)

    And when you think of it, the actual machine-code generated by the compiler will look like that as at the machine level there is only jump (aka goto) and conditional jump

  • Dyspeptic Curmudgeon (unregistered)

    Sometimes, you want the 'else' part early/first, since it is very short (as in, 'Die. Die now.') and the actual if is many lines of babble.

  • (nodebb) in reply to Conradus

    I thought this was familiar:

    https://thedailywtf.com/articles/When_A_Problem_Comes_Along,_You_Must_skipit

  • (nodebb)

    That looks like the coding style used all over OpenSSL's crypto code, all error handling is 'goto err' which is actually the normal exit except it skips some cleanup and assumes some status code set at the start of the function still indicates failure at the point when it returns.

  • WTFGuy (unregistered)

    I can recall writing code in the 1970s in languages that did not have an else clause as part of their if statement. I hope this code doesn't date from then. But it might.

    I'm not sure which is more horrifying: the idea this stuff might be (multi-ported) legacy from then, or this stuff might be more current stuff written by clueless morons. Either scenario is a disaster. Just different kinds of disaster.

  • (nodebb) in reply to WTFGuy

    More likely the original coder dates from then, and hasn't learned any new tricks like this fancy fandangled "else clause" in the decades since.

  • löchlein deluxe (unregistered)

    "to at least keep the codebase consistent" is a very something way of saying "so the previous dude has no excuse not to touch the code anymore". Been there, seen that.

  • Ralf (unregistered)

    Some folks seem to imply the authors of such code are either stupid or morons. I respectfully disagree. This is textbook psychopath.

    I'm also sadly reminded this is a common pattern in DOS CMD/BAT files. And unfortunately I still get to write some of these from time to time.

  • Alan (unregistered)

    It made me feel really ancient when, in the course of a house clearance, I found a Fortran-77 course handout from my undergraduate days containing the earnest advice: "Don't nest [those new-fangled] block-IFs more than three deep; use an occasional GOTO if necessary".

    Ralf: If Bourne shell scripting is like trying to play the piano in boxing gloves; DOS BAT scripting is like trying to play the piano in boxing gloves from inside a straitjacket.

  • (nodebb)

    "too many just followed the patterns that were already there."

    Decisions"

    1. Follow the pattern that has been established - one way of doing things: low cognitive load.
    2. Refactor an inappropriate pattern globally to be the miimum number (ideally 1) "appropriate patterns.
    3. Introduce more patterns leaving other places with "inappropriate patterns".

    I try to avoid #3 like the plague. There is often restrictions placed by management inhibiting #2, so #1 actually becomes the best....

  • (nodebb)

    "too many just followed the patterns that were already there."

    Decisions"

    1. Follow the pattern that has been established - one way of doing things: low cognitive load.
    2. Refactor an inappropriate pattern globally to be the miimum number (ideally 1) "appropriate patterns.
    3. Introduce more patterns leaving other places with "inappropriate patterns".

    I try to avoid #3 like the plague. There is often restrictions placed by management inhibiting #2, so #1 actually becomes the best....

  • (nodebb)

    "too many just followed the patterns that were already there."

    Decisions"

    1. Follow the pattern that has been established - one way of doing things: low cognitive load.
    2. Refactor an inappropriate pattern globally to be the miimum number (ideally 1) "appropriate patterns.
    3. Introduce more patterns leaving other places with "inappropriate patterns".

    I try to avoid #3 like the plague. There is often restrictions placed by management inhibiting #2, so #1 actually becomes the best....

  • WTFGuy (unregistered)

    We heard you the first time. :) Just kidding.

    Agree completely. BTDT. Though I'd rephrase that slightly as "... so #1 actually becomes the least bad choice."

  • Andrew Klossner (unregistered) in reply to Yazeran1

    The first assembly language I learned was the DEC PDP-10. It includes a sheaf of instructions that conditionally skip the following instruction, such as "Add One and Skip if Less than or Equal to zero". This works because all instructions are the same length: one 36-bit word.

  • hasseman (unregistered)

    Looks like their programmer tried to code as FORTRAN IV (66). It only had an IF but no else, at least on HP3000 You simulated else with GOTO's

  • BrainDeadCoder (unregistered)
    Comment held for moderation.
  • Grunthos the Flatulent (unregistered) in reply to TheCPUWizard
    Comment held for moderation.
  • (nodebb)

    Gloriously turing-complete

  • Mohit (unregistered)
    Comment held for moderation.

Leave a comment on “Else To”

Log In or post as a guest

Replying to comment #591941:

« Return to Article