go generics tutorial - golang finally has generics

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ก.พ. 2025

ความคิดเห็น • 66

  • @cryonixpod365
    @cryonixpod365 2 ปีที่แล้ว +1

    Brilliantly explained. Understood in one go :D.

    • @ThomasLanghorst
      @ThomasLanghorst  2 ปีที่แล้ว +1

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

  • @inujohn2124
    @inujohn2124 3 ปีที่แล้ว +1

    I really enjoyed this video. Thanks Thomas! 😁

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว

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

  • @joseanmartinez
    @joseanmartinez 3 ปีที่แล้ว +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  3 ปีที่แล้ว

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

    • @joseanmartinez
      @joseanmartinez 3 ปีที่แล้ว +1

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

  • @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!

  • @esra_erimez
    @esra_erimez 3 ปีที่แล้ว +4

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

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว

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

  • @barryblack8332
    @barryblack8332 3 ปีที่แล้ว +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  3 ปีที่แล้ว +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.

  • @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 2 ปีที่แล้ว

      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 2 ปีที่แล้ว +1

      @@kamilziemian995 Try Rust. th-cam.com/video/4O-lXoI2opA/w-d-xo.html

    • @kamilziemian995
      @kamilziemian995 2 ปีที่แล้ว

      @@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 2 ปีที่แล้ว +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.

  • @kps2642
    @kps2642 2 ปีที่แล้ว +1

    Really great video

    • @ThomasLanghorst
      @ThomasLanghorst  2 ปีที่แล้ว

      Thank you very much! Glad you enjoyed it.

  • @kaituo1803
    @kaituo1803 3 ปีที่แล้ว +1

    This is a wonderful video. Liked and subscribed!

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว

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

  • @esra_erimez
    @esra_erimez 3 ปีที่แล้ว +4

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

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว

      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!

  • @sakthiv3l
    @sakthiv3l 3 ปีที่แล้ว +1

    Thanks for the well explained video

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว

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

  • @AlessandroBottoni
    @AlessandroBottoni 3 ปีที่แล้ว +1

    Excellent video! Kudos!

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว

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

  • @Baile_an_Locha
    @Baile_an_Locha 3 ปีที่แล้ว +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  3 ปีที่แล้ว +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 2 ปีที่แล้ว +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  2 ปีที่แล้ว

      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.

  • @baxiry.
    @baxiry. 3 ปีที่แล้ว +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  3 ปีที่แล้ว +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. 3 ปีที่แล้ว +4

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

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว +2

      yeah, I feel the same way!

    • @donnacasterr6223
      @donnacasterr6223 3 ปีที่แล้ว +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  3 ปีที่แล้ว +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. 3 ปีที่แล้ว +1

    very nice and useful content

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว

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

  • @stephenkrus
    @stephenkrus 3 ปีที่แล้ว +1

    💎✨👍

  • @mbesida
    @mbesida 3 ปีที่แล้ว +1

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

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว

      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 3 ปีที่แล้ว +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  3 ปีที่แล้ว

      Awesome info, thanks for explaining and sharing!

  • @remymi902
    @remymi902 3 ปีที่แล้ว +1

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

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว

      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.

  • @adanjsuarez
    @adanjsuarez 3 ปีที่แล้ว +1

    Yeah 😜

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว

      Thanks for the comment! I really appreciate it!

  • @Kavinnathcse
    @Kavinnathcse 3 ปีที่แล้ว +1

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

    • @ThomasLanghorst
      @ThomasLanghorst  2 ปีที่แล้ว

      Nice to see, that you like my jokes :D

  • @baxiry.
    @baxiry. 3 ปีที่แล้ว +1

    nice

  • @Luix
    @Luix 3 ปีที่แล้ว +1

    cloud functions on gcp just accept go 1.16…

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว +1

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

  • @kamilziemian995
    @kamilziemian995 2 ปีที่แล้ว +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"? 😁

    • @ThomasLanghorst
      @ThomasLanghorst  2 ปีที่แล้ว +1

      😂😂😂 You are absolutely right Kamil!

  • @microdevelopers
    @microdevelopers 3 ปีที่แล้ว +2

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

    • @ThomasLanghorst
      @ThomasLanghorst  3 ปีที่แล้ว

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

  • @doezage
    @doezage 3 ปีที่แล้ว +1

    Rust >>>

  • @PawelMucha
    @PawelMucha 3 ปีที่แล้ว

    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.