go generics tutorial - golang finally has generics

Поделиться
HTML-код
  • Опубликовано: 18 сен 2024

Комментарии • 66

  • @joseanmartinez
    @joseanmartinez 2 года назад +5

    Hey Thomas! Really enjoyed this video. Love that intro, all the different images and the music/sound effects throughout. It was really clear, easy to follow and understand and well explained. I haven't learned GO yet, but seems like a cool language! I know making these videos is not an easy task so keep up the awesome work!

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      wow Josean, I really appreciate your help for the channel! Thank you so very much!!! And thanks for the awesome feedback!

    • @joseanmartinez
      @joseanmartinez 2 года назад +1

      @@ThomasLanghorst Keep going at it! Really appreciate you’re support over at my channel as well!

  • @esra_erimez
    @esra_erimez 2 года назад +4

    Freddy Krueger called and wants his shirt back. Also, great video.

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      hahahahaha, I knew that someone would point that out :D I kind of like it though. It's very comfy.

  • @cryonixpod365
    @cryonixpod365 2 года назад +1

    Brilliantly explained. Understood in one go :D.

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад +1

      What a pun :D But thanks man, really appreciated!

  • @2002budokan
    @2002budokan 2 года назад +6

    Finally, a language emerged that could surpass the elegance and beauty of C.

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад +2

      Hi. It makes me happy to hear that you like the language. To be honest, my experience with C is practically non existent. But I heard from people who used it a lot, that they also liked it a lot aswell.

    • @kamilziemian995
      @kamilziemian995 Год назад

      This is one of the reasons that I want to learn Go: its C-like elegance and beauty. At the same time, when you have garbage collector, you can debate if it give or take some elegance from the language. I'm still split on this question.

    • @2002budokan
      @2002budokan Год назад +1

      @@kamilziemian995 Try Rust. ruclips.net/video/4O-lXoI2opA/видео.html

    • @kamilziemian995
      @kamilziemian995 Год назад

      @@2002budokan Rust is already in my top 3 languages to I want to learn. But it has very different wibe that C. C is about giving you right tool, but nothing more (and their choice of "right tools" is not always right). Rust look to me as features extravaganza.

    • @2002budokan
      @2002budokan Год назад +1

      @@kamilziemian995 Rust compiler don't let you make memory-leak mistakes. Very clever compiler. It does take some time getting used to, but not too long. Compare it with C++ not with C. Don't waste time start with Rust. I did it and didn't regret.

  • @barryblack8332
    @barryblack8332 2 года назад +4

    As a c# developer, I found it strange that Go did not use generics and enums. My friends and the internet were like "it does not need it".
    The look on the faces now... I love it.

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад +1

      Yeah I totally get that. As a former Java developer, it felt totally strange that go does not have concepts like inheritance or generics. But now with generics...the world is becoming a better place :D
      Thanks for the comment, btw! Really appreciated.

  • @aleks_saint
    @aleks_saint 2 года назад +1

    That is truly a nice way to put it, thank you

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      Your absolutely welcome! I'm happy you liked it!

  • @inujohn2124
    @inujohn2124 2 года назад +1

    I really enjoyed this video. Thanks Thomas! 😁

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      Hey John, thank you so much for the comment. I am glad that you enjoyed it.

  • @esra_erimez
    @esra_erimez 2 года назад +4

    In my humble opinion, I think it is syntactic sugar.

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      I can totally understand your opinion. I think it depends on your programming style as well as the applications you write. For me, who often needs to convert from string to bools, floats, ints or timestamps, generics are a blessing. I can get rid of so much code now and replace it with generic functions.
      But I can totally understand since in many cases func f(v interface{}) is enough.
      Thanks for the comment and your opinion!

  • @kps2642
    @kps2642 2 года назад +1

    Really great video

  • @kaituo1803
    @kaituo1803 2 года назад +1

    This is a wonderful video. Liked and subscribed!

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      Hey Kai. Thank you very much!!! I am very happy you liked it.

  • @sakthiv3l
    @sakthiv3l 2 года назад +1

    Thanks for the well explained video

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      Thank you very much! I am very glad that you liked it!

  • @AlessandroBottoni
    @AlessandroBottoni 2 года назад +1

    Excellent video! Kudos!

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      Hey Alessandro. Thank you so much! I am glad you liked it.

  • @stephendelacruzone
    @stephendelacruzone 2 года назад +1

    💎✨👍

  • @baxiry.
    @baxiry. 2 года назад +1

    very nice and useful content

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      Hey bashiry. Thank you so very much for the comment! I really appreciate it!

  • @Baile_an_Locha
    @Baile_an_Locha 2 года назад +5

    I’m a hardcore ‘Modern C++’ developer but have been doing some Go programming recently on a pet project in my spare time, The absence of generics is driving me nuts, so I’m very much looking forward to getting my hands on this. Now if only they would give us exceptions…

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад +3

      Welcome to the gophers club! Yeah, i have to say that missing generics, missing exceptions and no real enums are a things that drove me crazy when I was learning go. As for exceptions, you can try to use panic and recover. I hate it to be honest:D It just feels super dirty. But you can try it out. Maybe it works for you. Let me know if you did and how your experience with it was please. Maybe I did something wrong ;)

    • @a0um
      @a0um Год назад

      I guess we won’t get exceptions but sum types instead, eg Either[Result, error]

  • @boot-strapper
    @boot-strapper Год назад +1

    am I weird that I think its better without generics? like we are using a statically typed language so we can know for sure what's happening. making it more generic makes things more vague and opens up possible unplanned uses for our functions.

    • @ThomasLanghorst
      @ThomasLanghorst  Год назад

      Yes, you are weired 🤣 Just kidding. I can understand your point. I guess it comes down to personal preference. I have been waiting for generics for a whole while and am glad that they are in this language. Coming from Java, I am used to generic and OOP programming. That's why I missed them when I switched to Go.

    • @a0um
      @a0um Год назад

      I appreciate having generics to remove the boilerplate code required to process collections.

    • @a0um
      @a0um Год назад

      I reckon generics will also allow to replace ‘interface {}’ with a constrained generic type , thus removing vagueness.

  • @remymi902
    @remymi902 2 года назад +1

    thanks, great video. I just hope Enum will be next.

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      Thanks for the comment! To be honest...I do not miss enums at all, since I can define my own types. Just like I did with weekdays. Is there something I am missing?

    • @a0um
      @a0um Год назад

      I guess the difference is that Enums are a closed set of values. That means a switch statement can warn you if you haven’t covered all the cases not specified a default case.
      Some people consider this useful because when a new requirement turns into a new value in the enum, the compiler will flag all the switch statements that need to be updated.
      I’ve seen “hacks” to get this behavior and they look ok to safeguard critical sections.

  • @Kavinnathcse
    @Kavinnathcse 2 года назад +1

    Let me try to translate it into human language 🤣🤣 .. Great content.. Tnx

  • @kamilziemian995
    @kamilziemian995 Год назад +1

    Rob "Commander" Pike said that more proper name for "Go's generic" is "parametric polymorphism". Do you still want to complain about "scientific gibberish"? 😁

  • @baxiry.
    @baxiry. 2 года назад +1

    The Go community was and still is divided. Between a "simple, even if it is ugly"s team, and "pretty, even if it is complex"s team

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад +1

      yes, you are right! The battle is still going on. Usually I favor the "simple, even if it is ugly" team. But in case of generics, I am all in "pretty, even if it is complex". It's probably due to my java background. What is your opinion on that topic?
      Thanks for the comment btw! Much appreciated!

    • @baxiry.
      @baxiry. 2 года назад +4

      @@ThomasLanghorst Frankly, libraries will become more clear and beautiful with generic. I will definitely love it.

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад +2

      yeah, I feel the same way!

    • @donnacasterr6223
      @donnacasterr6223 2 года назад +3

      @@baxiry. That is the biggest benefit of Generics IMO. Even the "pure" Golang standard library has places where you could see Generics would have made this more intuitive and easy to use

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад +1

      You are absolutely right Donna. I would love to see some statistics on how much code they were able to get rid of. I need to keep my eyes open 👀

  • @baxiry.
    @baxiry. 2 года назад +1

    nice

  • @mbesida
    @mbesida 2 года назад +1

    This is very similar to what is known as "type classes" in other languages

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      That is actually quite interesting. What languages are you speaking of? To be honest, I haven't heard of the term "type classes". Or I am completely spacing out right now :D I know that in Java, C++, Python and TypeScript it is called generics. These are the OOP languages I used so far.
      Thanks for the comment btw!

    • @mbesida
      @mbesida 2 года назад +2

      @@ThomasLanghorst I meant in Scala and Haskell(probably typescript also already has something similar). Specifically the exact same mechanism of "constraints" presented in this video is very similar to Scala's "context bound"

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      Awesome info, thanks for explaining and sharing!

  • @adanjsuarez
    @adanjsuarez 2 года назад +1

    Yeah 😜

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      Thanks for the comment! I really appreciate it!

  • @microdevelopers
    @microdevelopers 2 года назад +2

    Thanks. You have great content. Please more on go. Don't deviate and start making unnecessary videos like others.

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад

      Hey, thanks for the feedback and nice comment. What do you mean by "unnecessary videos"?

  • @Luix
    @Luix 2 года назад +1

    cloud functions on gcp just accept go 1.16…

    • @ThomasLanghorst
      @ThomasLanghorst  2 года назад +1

      oh wow...thanks for sharing! I did not know that.

  • @doezage
    @doezage 2 года назад +1

    Rust >>>

  • @PawelMucha
    @PawelMucha 2 года назад

    Ok, now let's do this:
    func Zip[K comparable, V any](keys []K) func(values []V) map[K]V {
    // code here...
    }
    It should turn one slice into keys, and the second one into values of a resulting map, like this:
    Zip(someKeys)(someValues)
    Implement it and try to invoke it.
    Then tell me if the generics in Go are so awesome.