>be GOTO. >Doesn't blow up the stack like recursion. >1:1 mapping to machine code

>be GOTO
>Doesn't blow up the stack like recursion
>1:1 mapping to machine code
>easy to understand as long as its done within 30 LOC or so
>Breaks out of loops and conditional statements like a dream
>Hated by many

why?

  1. 3 weeks ago
    Anonymous

    >loops are recursion
    hello dunning kruger, took your first C class?

    • 3 weeks ago
      Anonymous

      Cargo-culting. There are literally people who think you shouldn't use gotos for cleanup or breaking out of nested loops.

      In terms of stack space they are when they're unrolled. Which is what OP is getting at, especially in the old days manual gotos were usually needed to get effective tail-call optimization.

      C's goto statment is not the same as the one that "GOTO considered harmful" was written about. C has better gotos since they're scoped to the function. The old kind did not.

      C has a goto that goes between scopes and codegen units, it's called longjmp.

      • 3 weeks ago
        Anonymous

        >In terms of stack space they are when they're unrolled.
        Are you fucking retarded? You're not going to blow up your stack with a while loop.

        • 3 weeks ago
          Anonymous

          >You're not going to blow up your stack with a while loop.
          You're the reason musl has 20,000 wontfix bugs about making the stack bigger.

          • 3 weeks ago
            Anonymous

            No musl.
            No stack.
            No C.
            https://github.com/nemasu/asmttpd

      • 3 weeks ago
        Anonymous

        I am OP and loops literally have nothing to do with the stack, I was talking about literal recursion where you call a function inside of itself

      • 3 weeks ago
        OP

        The compiler will intentionally convert loops to recursive functions sometimes?

      • 3 weeks ago
        Anonymous

        >tail-call optimization.
        useless luxury
        there is no algorithm which requires recursion to work, it's only supported at all to enable low iq people to write code

        • 3 weeks ago
          Anonymous

          see

          >Any other recursion can emulated with loops and arrays
          False. Try re-implement http://www.eprg.org/computerphile/ackermann.c sans recursive calls.

          • 3 weeks ago
            Anonymous

            I don't think you know how computers work.
            There is no such thing as recursion at the instruction level.
            It's just pushing shit onto the stack and jumping.
            You can always do that yourself in C and most other high level languages.

            • 3 weeks ago
              Anonymous

              If you have to push the exact same function address onto the stack several times and pass a value all the way back up, that's recursion. That is not the same as a loop where you can just keep a value in a register and iterate on it. Just re-implement the Ackerman algorithm with a loop(s) if you think it's so easy.

              • 3 weeks ago
                Anonymous

                There are restrictions to longjmp. You can only jump to a function whose frame still exists on the stack. It's impossible to do
                jmp_buf a() {
                jmp_buf jb;
                if (setjmp(jb))
                return jb;
                //do something
                }
                int main(int argc, char **argv) {
                jmp_buf jb;
                jb = a();
                longjmp(jb, 1);
                }

                Or more precisely, "the behavior is undefined. Some kind of subtle or unsubtle chaos is sure to result"

                when fixing a recursive implementation by turning it into loops, there is no requirement to use separate C functions
                looks like you think it's impossible because you've adopted, for no reason, artificial limitations to your thinking

              • 3 weeks ago
                Anonymous

                Your silence speaks for itself.
                And no this isn't my homework, it's an example that an Oxford professor used explicitly to show that not every recursive function can be made into loops.

              • 3 weeks ago
                Anonymous

                The professor is a brainlet then.
                How do you think the CPU does it?
                Call/ret are convenience instructions, they don't perform unique functionality that can't be done with a combination of other instructions (i.e. a loop).

              • 3 weeks ago
                Anonymous

                I'm not reading your post because it does not contain a code block that re-implements the Ackerman function as one or more loops and no recursive function calls.

              • 3 weeks ago
                Anonymous

                I'm not doing work for you, homosexual, but this is a long solved problem.

              • 3 weeks ago
                Anonymous

                Thank God for C, this shit is barely readable.

              • 3 weeks ago
                Anonymous

                >How do you think the CPU does it?
                Recursively: https://godbolt.org/z/M18va5az6

              • 3 weeks ago
                Anonymous

                >it's an example that an Oxford professor used explicitly to show that not every recursive function can be made into loops.
                Holy shit, I heard the quality of the faculty at famous universities was dropping, but I didn't think it was this bad.

            • 3 weeks ago
              Anonymous

              0x0001: NOP
              0x0002: CALL 0x0001

              looks like recursion to me

              • 3 weeks ago
                Anonymous

                recursion isn't real, it's an abstraction to help brainlets understand loops

              • 3 weeks ago
                Anonymous

                Loops aren't "real" either, retard.

              • 3 weeks ago
                Anonymous

                Tie a loop around your neck and jump and tell me they aren't real.

        • 3 weeks ago
          Anonymous

          No, recursion is used by high iq people to save time and focus on the real problems.

      • 3 weeks ago
        Anonymous

        There are restrictions to longjmp. You can only jump to a function whose frame still exists on the stack. It's impossible to do
        jmp_buf a() {
        jmp_buf jb;
        if (setjmp(jb))
        return jb;
        //do something
        }
        int main(int argc, char **argv) {
        jmp_buf jb;
        jb = a();
        longjmp(jb, 1);
        }

        Or more precisely, "the behavior is undefined. Some kind of subtle or unsubtle chaos is sure to result"

      • 3 weeks ago
        Anonymous

        >There are literally people who think you shouldn't use gotos for cleanup
        This is strictly unnecessary in C++ and Rust due to RAII. The nested loops use case is correct for C++ at least, however.

        Thank God for C, this shit is barely readable.

        >this shit is barely readable
        That's pseudocode. How retarded are you?

        >Is Bjarne Stroustrup the only person that cares about compiler optimizations these days?
        He's the only one (other than the Rust devs) with the gall to claim that making the optimizer do arbitrarily-more work per scope based on generic interfaces and encapsulations makes the code faster.

        Yeah, well, we're not talking about generic interfaces. We're talking about a fucking for loop. For loops are bitch easy to optimize.

    • 3 weeks ago
      Anonymous

      I just had recursion on my mind because I was writing something in python, and I had to use recursion to do something, but it would have been easier to do it with GOTO

  2. 3 weeks ago
    Anonymous

    C's goto statment is not the same as the one that "GOTO considered harmful" was written about. C has better gotos since they're scoped to the function. The old kind did not.

  3. 3 weeks ago
    Anonymous

    Use ATS, write C with type-level recursion checker.

  4. 3 weeks ago
    Anonymous

    Only tail end recursion is practical in real world scenarios. Any other recursion can emulated with loops and arrays without the downside of blowing up the stack.

    • 3 weeks ago
      Anonymous

      >Any other recursion can emulated with loops and arrays
      False. Try re-implement http://www.eprg.org/computerphile/ackermann.c sans recursive calls.

    • 3 weeks ago
      OP

      I know that, and I have used it before in languages that don't have GOTO and I thought it was a bullshit solution compared to the GOTO I would have used in C

  5. 3 weeks ago
    Anonymous

    Brainlets is the answer, as usual.

  6. 3 weeks ago
    Anonymous

    I remember using GOTO in visual basic for excel macros and it was a very very bad time.

  7. 3 weeks ago
    Anonymous

    >1:1 mapping to machine code
    That's not actually a desirable property. You want the code you're using to be fast, regardless of whether the resulting machine code is readable. Higher level control flow structures may be easier to optimize.

    >easy to understand as long as its done within 30 LOC or so
    And what if it isn't? Do you expect all of your functions to be small? And do you think the use of multiple GOTOs might complicate your ability to understand things?

    >Breaks out of loops and conditional statements like a dream
    You have mentioned the one legitimate use case of GOTO. Now tell me why you would use it anywhere else. Because in Rust, we've managed to completely do away with GOTOs in favor of labeled breaks. You can assign a label to a loop and use the break statement with that label to escape inner loops. But you can't use these labels in any other context at all. There is no GOTO to create an alternative to standard looping. And I fail to see an area where GOTO would be useful over other constructs.

    • 3 weeks ago
      Anonymous

      >Regurgitated Bjarnism nonsense
      >Concern trolling
      >What if you used a goto but worse instead

      • 3 weeks ago
        Anonymous

        >Bjarnism
        Now that's a term I don't think I've seen before. Is Bjarne Stroustrup the only person that cares about compiler optimizations these days?
        >Concern trolling
        Concern trolling is a term used for those arguing in bad faith. It is not a term you can apply generally to any argument that has the tone of being concerned. I am providing a counterexample here because the debate we are having is on the merits of using GOTO. Given that the subject matter is programming, there is an expectation that someone might show a degree of concern because the majority of programming is not a solo activity. The unmaintainable swill that you write has to be read by others and expanded upon by others to add new features and fix bugs. As we are both anonymous, it it not possible for me to know if I will ever have to work alongside you, or with someone you might pass on your knowledge of programming with. Therefore, it is in my rational self interest to implore you to use better abstractions.
        >What if you used a goto but worse instead
        Part of what makes a good abstraction is the intelligent use of limitations. We know from practice that code that uses GOTOs everywhere is very difficult to read and maintain. But we also know that there are a handful of uses where other abstractions have failed to replace GOTOs. By expanding what "break" is allowed to do, and by allowing RAII to handle cleanup during an early return, we find that every use of GOTO in C that was not previously provided by other high level structures in C (i.e. for/while loops, break, continue, return), can now be handled conveniently in Rust.

        • 3 weeks ago
          Anonymous

          >Is Bjarne Stroustrup the only person that cares about compiler optimizations these days?
          He's the only one (other than the Rust devs) with the gall to claim that making the optimizer do arbitrarily-more work per scope based on generic interfaces and encapsulations makes the code faster.

    • 3 weeks ago
      Anonymous

      1: your post literally reads like those sniffling retards that people like to make fun of

      2: JMP is plenty fast, and those labelled breaks in rust just sounds like GOTO/JMP with extra steps

      Third, I diden't say GOTO should be used everywhere, but sometimes it really just does feel like the most straightforward and simple solution,, so why get rid of it?

  8. 3 weeks ago
    Anonymous

    https://en.wikipedia.org/wiki/COMEFROM

  9. 3 weeks ago
    Anonymous

    >why?
    It turns a software program from an abstract mathematical equation to something that cannot be represented in purely logical, theoretical terms. Line order is just an accident.

  10. 3 weeks ago
    Anonymous

    Because structured programs (if-while-switch-call-return) are easier to analyse than generalized state machines, both for programmers and for compilers.

    Back in the day, a lot of programmers would just use goto for everything. Why use an if block with indentation when you can use an if-goto? Why use a while loop when you can use an if-goto? Why use a function call when you can just goto, and have some logic at the end for where to goto after each time?

    This is where the term "spaghetti code" comes from, because they'd make stuff where if you flowchart it to try and make sense of what the code's doing, it looks like a plate of spaghetti: the lines cross everywhere, and you still have no idea what's going on. So goto got a reputation as something mainly for bad programmers who make disorganized code.

    The sensible message, "Don't use goto (except in the rare cases it's actually the simplest, clearest way to efficiently do something)." got dumbed down into "goto considered harmful" by midwits who weren't smart enough to understand the cases where goto is still the best way. And a lot of these guys were teachers, managers, writers, etc. So a whole generation of programmers got trained not to use goto, and told it was a mistake for goto to have been included in languages at all, and they went out, and they made languages with no goto and no reasonable substitute for it.

  11. 3 weeks ago
    Anonymous

    Because some vastly overrated ivory tower CS loser said it was "harmful" 60 years ago, and the autistic sheep that computer programming tends to attract are very low on actual critical thinking skills, preferring to parrot the opinions of some trusted/popular individual, no matter how wrong they are.

Your email address will not be published. Required fields are marked *