Level Up Your Golang: 5 Concepts You Need to know

Поділитися
Вставка

КОМЕНТАРІ • 49

  • @orterves
    @orterves 4 місяці тому +8

    13:36 avoid weird syntax, refactor the code to put the inner loops into a function and replace the goto with a return

  • @CrayonEater9845
    @CrayonEater9845 6 місяців тому +27

    I've been writing Go for a month, but have 5 years in industry. These are all pretty basic concepts in Go. Also don't use goto. It destroys control flow and there are other ways to do what it enables. If you look at C, goto exists, but you really only see its use when taking emergency recovery actions like in the Linux kernel.

    • @FloWoelki
      @FloWoelki  6 місяців тому +7

      I agree with you, but it's definitely good to know the concepts.
      Sure, they do destroy in some way the control flow, but when used correctly, they can simplify things a lot and make your code even more readable and maintainable. Even the official standard library uses `goto`.

    • @DavidSmith-ef4eh
      @DavidSmith-ef4eh 5 місяців тому

      c# implementation of LINQ and some of their other features use goto. I assume there is a usecase for everything, its' just discouraged since people would abuse it.

    • @hkupty
      @hkupty 4 місяці тому

      Goto is usually considered harmful but can be employed for good in error handling and cleanup. However, I feel like golang's defer do a much better job here so I would refrain from goto unless strictly necessary. That would usually be, as you said, performance critical codepaths which should not be taken lightly.

    • @benitoe.4878
      @benitoe.4878 2 місяці тому

      Goto was put into Go for good reason and was combined with support for labels and some sensible restrictions and admonitions in the language specification. So it should be used--when appropriate. I feel the primary use case is precisely then, when you absolutely HAVE TO break the control flow. So far, this happened to me only once in a situation where this was the best solution I could come up with in regard to an algorithmic problem. So I think this is mostly for these kinds of things.

  • @grouponsurgeon
    @grouponsurgeon 5 місяців тому +5

    You might not have set out to explain bit shifting but you did a pretty good job of simplifying the concept

    • @FloWoelki
      @FloWoelki  5 місяців тому

      Thank you :) I might make a video about bit shifting in the future.

  • @Blonar257
    @Blonar257 4 місяці тому

    ich bin gerade dabei Go zu lernen. Vor ein paar Wochen waren die Inhalte deiner Videos noch etwas tricky für mich, aber so langsam geht es ;-) Toller Kontent, vielen Dank dafür. Sehr sehr hilfreich

    • @FloWoelki
      @FloWoelki  4 місяці тому

      Freut mich sehr, dass es dir weiterhilft! :)

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

      I dunno german but i bet my ass he said it's been great learning Go in the first sentence

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

      @@last_fanboy_of_golb Not quite, but it's close. It's more like in the direction: "I am currently learning go, and a few weeks ago it was tricky, but now he is getting comfortable with it"

  • @matthew1106
    @matthew1106 7 місяців тому +2

    More videos like this please!

    • @FloWoelki
      @FloWoelki  6 місяців тому

      Sure, I'll try my best!

  • @Diego-em1mb
    @Diego-em1mb 23 дні тому

    Do you want something advance well, in the terms of golang, you know the delete func right?, now check out the clear Func, also the code of the std library of golang is pretty straight foward, is good to give it a look

  • @a_maxed_out_handle_of_30_chars
    @a_maxed_out_handle_of_30_chars 5 місяців тому +1

    simple and to the point, thank you :)

    • @FloWoelki
      @FloWoelki  5 місяців тому +1

      Glad it helped! :)

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

    I really like your video editing skills, how can I achieve a similar look in my videos? which program are you using for the edits?

  • @cariyaputta
    @cariyaputta 6 місяців тому

    Nice golang focused videos, added to my library.

    • @FloWoelki
      @FloWoelki  6 місяців тому +1

      That's awesome, thank you :)

  • @KanishkaDilshan
    @KanishkaDilshan 5 місяців тому

    Great content!

    • @FloWoelki
      @FloWoelki  5 місяців тому +1

      Thank you so much! :)

  • @adanpalma4026
    @adanpalma4026 5 місяців тому

    For me go to is label break just for bring some clarity. Because goto outherloop is better that just break

  • @thewalkthroughmaking
    @thewalkthroughmaking 5 місяців тому

    From now on I'm going to start quoting "This is somehow a problem, cuz it's not really beautiful and it is really really ugly" daily hahahaha

    • @FloWoelki
      @FloWoelki  4 місяці тому

      That's the spirit :D

  • @sehbazrafik
    @sehbazrafik 7 місяців тому

    amazing video, can you please have your dev setup on the laptop + desk tour video.

  •  12 годин тому

    counter is not concurrent safe

  • @李伟鸣
    @李伟鸣 5 місяців тому

    good stuff!

  • @happy..1907
    @happy..1907 Місяць тому

    It would be pretty much better if you skip saying pretty much so you should pretty much stop saying pretty much.
    Just kidding, thanks for the efforts to make Golang popular.

  • @brandonbraner
    @brandonbraner Місяць тому

    1:38 man I bet this guy dishes out mean insults. Not only is this not beautiful... it is really really ugly. If those const's had feelings they would be

  • @MattRobinsonDev
    @MattRobinsonDev 6 місяців тому

    great stuff

  • @justinjustin4605
    @justinjustin4605 5 місяців тому

    what theme is that?

    • @FloWoelki
      @FloWoelki  5 місяців тому

      It's the GitHub theme :)

  • @wWvwvV
    @wWvwvV 4 місяці тому

    0:46 iota is not an acronym (for what?), it's a Greek letter. You spell it eota or yota.

  • @lemurza5236
    @lemurza5236 6 місяців тому +5

    Generally speaking you should avoid labels. They are one of the features of Go that hurt the language in a big way.
    Labels and Goto are horrible and should be avoided at all costs

    • @FloWoelki
      @FloWoelki  6 місяців тому +1

      I agree, generally speaking you should avoid these, especially for simple flows.
      However, they do exist for a reason, and even the standard library of Golang uses both concepts.
      Obviously, they should be used judiciously. But, especially for things like simplifying error handling and cleanup code (in some cases) can lead to more readable and maintainable code.

    • @adanpalma4026
      @adanpalma4026 5 місяців тому

      @@FloWoelkiyes that is the point.
      Its like a go sub or call func in long infinite chain call. Like call func1 and in func1 call func 2 and son on. In this case we are dividing and specialiating code but in a bad way of control. Is the same with labels in go. If you use in a propper way no problem. People are afraid of goto because of basic where you can go to anywhere in the code but labels in go are fantastic tool

  • @nandans2506
    @nandans2506 14 днів тому

    Don't use labels and goto, not a good practice, can make the code unreadable, it's not recommended to jump instructions like that

  • @richardbolanos50
    @richardbolanos50 6 місяців тому

    When it comes to the new keyword what is the difference between return new(Counter) and return &Counter{} if any. Is there a performance benefit by any chance

    • @loo_9
      @loo_9 6 місяців тому +2

      there should not be a performance difference, but the only way to truly know this is benchmarking.
      the compiler would recognize that the memory escapes the function scope so it has to be heap allocated. the only difference is that {} you can specify initial values

    • @FloWoelki
      @FloWoelki  6 місяців тому +2

      I agree; there shouldn't be any performance difference because the Go compiler optimizes both expressions similarly.
      I think this is a valuable discussion: groups.google.com/g/golang-nuts/c/GDXFDJgKKSs

    • @richardbolanos50
      @richardbolanos50 6 місяців тому +1

      @loo_9 and @FloWoelki thanks for taking the time to reply.

  • @DGDG0000000
    @DGDG0000000 4 місяці тому +1

    "goto nextIteration", in you rexample, is the same than "continue" keyword. But goto is well known since ever (asembly code even in micro-controler 8 bits) as an "inconditional jump". It is a bad practice there.

  • @esra_erimez
    @esra_erimez 5 місяців тому

    "Go To Statement Considered Harmful" -Edsger Dijkstra

    • @adanpalma4026
      @adanpalma4026 5 місяців тому

      😂 please. That was said in a context totallundiferent where go to was used indicriminated as in basic where you can jump to anywhwere in the code. This is no the case