CS101++ - What is`goto`?

Поділитися
Вставка
  • Опубліковано 8 чер 2024
  • ☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟
    Upcoming Workshop: Understanding Object Lifetime, C++ On Sea, July 2, 2024
    ► cpponsea.uk/2024/sessions/und...
    Upcoming Workshop: C++ Best Practices, NDC TechTown, Sept 9-10, 2024
    ► ndctechtown.com/workshops/c-b...
    github.com/lefticus/cpp_weekl... for open ended conversions about CS101++ videos
    T-SHIRTS AVAILABLE!
    ► The best C++ T-Shirts anywhere! my-store-d16a2f.creator-sprin...
    WANT MORE JASON?
    ► My Training Classes: emptycrate.com/training.html
    ► Follow me on twitter: / lefticus
    SUPPORT THE CHANNEL
    ► Patreon: / lefticus
    ► Github Sponsors: github.com/sponsors/lefticus
    ► Paypal Donation: www.paypal.com/donate/?hosted...
    GET INVOLVED
    ► Video Idea List: github.com/lefticus/cpp_weekl...
    JASON'S BOOKS
    ► C++23 Best Practices
    Leanpub Ebook: leanpub.com/cpp23_best_practi...
    ► C++ Best Practices
    Amazon Paperback: amzn.to/3wpAU3Z
    Leanpub Ebook: leanpub.com/cppbestpractices
    JASON'S PUZZLE BOOKS
    ► Object Lifetime Puzzlers Book 1
    Amazon Paperback: amzn.to/3g6Ervj
    Leanpub Ebook: leanpub.com/objectlifetimepuz...
    ► Object Lifetime Puzzlers Book 2
    Amazon Paperback: amzn.to/3whdUDU
    Leanpub Ebook: leanpub.com/objectlifetimepuz...
    ► Object Lifetime Puzzlers Book 3
    Leanpub Ebook: leanpub.com/objectlifetimepuz...
    ► Copy and Reference Puzzlers Book 1
    Amazon Paperback: amzn.to/3g7ZVb9
    Leanpub Ebook: leanpub.com/copyandreferencep...
    ► Copy and Reference Puzzlers Book 2
    Amazon Paperback: amzn.to/3X1LOIx
    Leanpub Ebook: leanpub.com/copyandreferencep...
    ► Copy and Reference Puzzlers Book 3
    Leanpub Ebook: leanpub.com/copyandreferencep...
    ► OpCode Puzzlers Book 1
    Amazon Paperback: amzn.to/3KCNJg6
    Leanpub Ebook: leanpub.com/opcodepuzzlers_book1
    RECOMMENDED BOOKS
    ► Bjarne Stroustrup's A Tour of C++ (now with C++20/23!): amzn.to/3X4Wypr
    AWESOME PROJECTS
    ► The C++ Starter Project - Gets you started with Best Practices Quickly - github.com/cpp-best-practices...
    ► C++ Best Practices Forkable Coding Standards - github.com/cpp-best-practices...
    O'Reilly VIDEOS
    ► Inheritance and Polymorphism in C++ - www.oreilly.com/library/view/...
    ► Learning C++ Best Practices - www.oreilly.com/library/view/...
  • Наука та технологія

КОМЕНТАРІ • 20

  • @LogicEu
    @LogicEu 3 місяці тому

    Goto represents the unconditional jump statement and combined with the conditional jump, aka if, it's one of the most important building blocks in computing and a fundamental assembly instruction.

  • @N....
    @N.... 3 місяці тому +2

    The only times I've used goto are when I needed to break multiple levels out of nested loops and couldn't easily utilize a better option like returning or a lambda or invalidating the loop conditions etc. - once labeled break and continue are available I guess that will eliminate the last reasonable use of goto.

  • @acf2802
    @acf2802 3 місяці тому +4

    I love when modern, young programmers bring up "goto considered harmful" any time you mention goto. They are completely unaware of the context in which it was written and believe it's simply one of the 10 programming commandments "thou shall never use goto."

    • @bloodgain
      @bloodgain 3 місяці тому

      This. And I was once one of those young programmers, as this was still the gospel when I was in college in the early '00s. The important thing to understand is that `goto` in modern languages, including C and C++, is not the same `goto` that Dijkstra was talking about. Modern `goto` is not allowed to cross function boundaries.
      The closest to old `goto` in C/C++ is `setjmp`/`longjmp`. Not only are there some reasonable uses of modern `goto`, the form Dijkstra warned about is still part of system languages for a reason.

    • @bloodgain
      @bloodgain 3 місяці тому

      Also, people like to forget that there's "never" and "programmer never". The latter really means, "only use it when there's really no better or equivalent option, and then only if you really know what you're doing -- if you're not 110% sure, you probably don't". But that's a lot to say. It's easier to say, "*You* shouldn't do this."

    • @acf2802
      @acf2802 3 місяці тому +2

      @@bloodgain My main point is that "goto considered harmful" was written in a time when "functions" were some newfangled invention that some FUDs hadn't yet adopted. I think the main point of it was to encourage people to start using functions and other higher level abstractions. Well, everyone is using functions today, so that paper is completely irrelevant now. People just quote the title and forget the reason why it was written.

    • @bloodgain
      @bloodgain 3 місяці тому

      @@acf2802 That is an excellent point, indeed! Context is crucial.

  • @dwarftoad
    @dwarftoad 3 місяці тому

    As you go on you should talk about how concepts build on each other. How is an if like a conditional goto; how is a function call and return like a superpowered goto. Can you create your own version of something like a function call and return in C++ with just goto? Also, a peek into assembly/machine pseudocode (e.g. simplified assembly code, Knuth's MIX, your own, etc.) that could be generated from these C++ concepts, and how that might be executed by a hypothetical CPU and memory system could be helpful too.

    • @cppweekly
      @cppweekly  2 місяці тому

      This is a good point, and something I did do in C++ Weekly one time: ua-cam.com/video/lW51OrNJAn8/v-deo.html

  • @TNothingFree
    @TNothingFree 3 місяці тому

    Goto comes from a low level statement like jump zero or jump non zero
    Jump to location x is assembly level,
    When you use goto you fail to utilize higher level code features since in c or cpp you no longer control directly the code pointer but only data.
    In low level code whete the code itself is built to control its own code execution i may understand the use - in embedded or embedded asm.
    But in othet contexts, it shoulsnt be used as there are better, more understandable features.

  • @thesorus
    @thesorus 3 місяці тому +1

    I'm waiting for the gosub video.

  • @maxaafbackname5562
    @maxaafbackname5562 3 місяці тому

    For everything there is a time & place.
    If it really was a thing to be never used, the keyword was removed from recent standards like C or C+×.
    Warned against bad usage should be still in place when learning programming.
    You always write structured code, and goto can have a place in that.
    You don't need goto to write spagetticode...
    Break out of multiple loops using goto is the most efficient way.
    For me more readable than additional loop conditions.
    Using goto for some exception handling is, for me, a nice way.

  • @kyleolson8977
    @kyleolson8977 3 місяці тому +2

    CS101++ Considered Harmful

  • @Minty_Meeo
    @Minty_Meeo 3 місяці тому

    I have used goto to emulate range-based for-else loops in C++ without a boolean flag. I have used goto to make one function more capable while avoiding code duplication. Goto is really neat, you just need to use it in moderation.

  • @Volker-Dirr
    @Volker-Dirr 3 місяці тому

    Hmm... a little bit few c++ code in this episode. I thought you show use nice and modern algorithms that can be much faster if they use (also) goto instead of "normal" flow control of high languarges (only). (But is was fun to see that old code again. I started coding on a Comodore PET 2001 as a kid)

  • @seventyfive7597
    @seventyfive7597 2 місяці тому

    goto is a **break** , goto is a **continue** , goto is a **return** that is not at the end of a function. All of these are allmost always indicative of bad factoring. Perhaps it's because I'm older than you Jason, but I consider all of these goto-s.

  • @kaanbalkaya
    @kaanbalkaya 3 місяці тому

    gw basic 🎉

  • @nextlifeonearth
    @nextlifeonearth 3 місяці тому +1

    I still use goto sometimes in C codebases. I think it's a reasonable alternative for RAII, given that C doesn't have it.

  • @ignacionr
    @ignacionr 3 місяці тому

    it doesn’t seem like you have a lot of actual CS university style knowledge, am I far out of line? you lack a number of concepts that the most basic CS professor would use.

    • @acf2802
      @acf2802 3 місяці тому +3

      I would consider that a complement.