Golang Generics is Officially HERE!! (Full Tutorial)

Поділитися
Вставка
  • Опубліковано 15 лип 2024
  • Golang Generics is Officially HERE!! (Full Tutorial)
    Golang Generics is finally out. It will make it easier for new and experienced programmers alike to use generics in Go. This video gives a rundown on the 3 main features of Go generics.
    -Type parameter
    -Type inference
    -Type set
    Enjoy watching!
    --
    Golang Dojo is all about becoming Golang Ninjas together. You can expect all kinds of Golang tutorials, news, tips & tricks, and my daily struggles as a Golang developer. Make sure to subscribe if you look forward to such content!
    Get Your Golang Cheat Sheet! - golangdojo.com/cheatsheet
    Git repos & notes - golangdojo.com/resources
    Golang Basics - • Golang Basics - Instal...
    Golang Informative - • How much do Golang dev...
    --
    Timestamps
    0:00 - Intro
    1:01 - The Go Generics
    1:32 - The 3 Main Features
    3:14 - Type Parameter
    6:01 - Type Inference
    8:56 - Type Set
    12:43 - Outro
    --
    #golang #goprogramming #golangdojo
  • Наука та технологія

КОМЕНТАРІ • 78

  • @GolangDojo
    @GolangDojo  2 роки тому +6

    📝Get your *FREE Golang Cheat Sheet* -
    golangdojo.com/cheatsheet

    • @vinceplatt8468
      @vinceplatt8468 Рік тому

      The cheat sheet doesn't seem to include generics. Am I missing something?

  • @lawrencejob
    @lawrencejob Рік тому +1

    This channel is exactly what I’ve been looking for; thank you

  • @vitiok78
    @vitiok78 2 роки тому +3

    After this video I am officially moving from Typescript to Go.
    Genetics are the necessity nowadays. Even the PHP crowd is waiting for them for a long time.
    Excellent!

  • @flipperiflop
    @flipperiflop Рік тому

    This really helped me to understand how generics work in general - I always thought it to be some kind of a "higher level" thing, but it really is just a placeholder in a way, allowing generalizing functions, but also constrain the types the function works with.

  • @prashantnavrange9514
    @prashantnavrange9514 2 роки тому

    very crisp and clear explanation of generics concept. thanks!

  • @ChristopheFerauge
    @ChristopheFerauge 2 роки тому +1

    Very well explained. You're not only a golang Ninja ... but also a teaching Ninja. Thank you very muvh.

  • @nicolito128
    @nicolito128 2 роки тому

    I'm learning go and all these new things are really exciting for me

  • @churraskindequeijo8418
    @churraskindequeijo8418 2 роки тому +3

    Let's go!!!, I will watch this one on my Java/JavaScript job 😂

  • @wolverine2970
    @wolverine2970 2 роки тому

    Great content! Thanks for the channel!

  • @quocnho
    @quocnho 2 роки тому +1

    Thanks for your sharing!

  • @jabuci
    @jabuci Рік тому

    It was crystal clear. Thanks!

  • @birqan
    @birqan 2 роки тому

    A very good instruction in go generics. Well done buddy.. 🥇

  • @RobDuarte
    @RobDuarte Рік тому

    Excellent video. Succinct and well organized. Thanks for this.

  • @ranilmadawalage1897
    @ranilmadawalage1897 2 роки тому

    Thanks for this. Really good content

  • @bavan1358
    @bavan1358 2 роки тому +1

    Finally!!!! 🔥🔥

  • @CarloLobrano
    @CarloLobrano 2 роки тому

    thanks for this video, it is quite clear 👍

  • @samme4life
    @samme4life 2 роки тому

    Good explanation. Thank you for sharing your knowledge.

  • @orlandoemilianogarciadiaz2531

    Amazing video!

  • @matheusgaldino8337
    @matheusgaldino8337 2 роки тому

    Great video!

  • @unamed6136
    @unamed6136 Рік тому

    amazing explanation, ty

  • @bxhehehehdhdhhd1443
    @bxhehehehdhdhhd1443 2 роки тому

    Cool vid, thanks for the help

  • @jose_code
    @jose_code 2 роки тому +5

    Golang is improving so fast. That is great.

  • @gerardgauthier4876
    @gerardgauthier4876 2 роки тому +5

    I'd love to see a generic binary tree written in GoLang.

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

    thank you bro

  • @flogginga_dead_horse4022
    @flogginga_dead_horse4022 2 роки тому +1

    finally!!! :)

  • @Zwartepiet777
    @Zwartepiet777 Рік тому

    thanks!

  • @mikeyo5154
    @mikeyo5154 2 роки тому +19

    Im learning Go and by coincidence started looking at generics today. Downloaded v1.18 and did some trials. Works well but my vscode ide has not caught up and shows some potential errors which are not real for the new compiler. Anyway, nice tutorial, thanks for your video 🙏

    • @quocnho
      @quocnho 2 роки тому +7

      I think, you need to update gopls for your vscode. Ctrl+shift+p then choose Go: Install & Update tool, then choose all. I am not sure to fix your errors, but please try.... have a nice day!

    • @mikeyo5154
      @mikeyo5154 2 роки тому +2

      @@quocnho thank you. That worked for me

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

    something I've recently done was needing to create a certificate generation function that could accept both RSA keys and EC keys, I did it slightly differently where it could accept any type and if it didn't mach a supported type it would error out. Now I should be able to go back and make it more strongly typed thanks to Generics

  • @mattgarelli1371
    @mattgarelli1371 2 роки тому +9

    Does allowing multiple types as an input have an effect on performance?

  • @jtcrew1
    @jtcrew1 Рік тому +1

    Great tutorial overall! Why did your min(sf, 0.2) return 0.3 (incorrect) when the generic type was defined as ~float64? This problem did not exist when the generic type was defined using "type set". Is this another example of the compiler not being compatible with the latest language additions?

  • @kentontroy
    @kentontroy 2 роки тому +10

    Thanks as usual! My only concern though is keeping golang minimally sufficient and succinct. That's what makes it awesome. When I see your examples, my first reaction is okay, soon someone will ask for overloading the operator

    • @codegambit2507
      @codegambit2507 2 роки тому

      Let's hope it doesn't get to that

    • @knabbagluon
      @knabbagluon Рік тому +2

      There is always a balance but generics were needed. I program a small app and option 1: Making X functions which do all the same
      2: generics.
      So thank god we got generics.

  • @vinaykumarva8538
    @vinaykumarva8538 2 роки тому

    we want more videos basic golang I'm from India waiting

  • @AkumetsuOne
    @AkumetsuOne 2 роки тому

    Which environment are you using to dev? And which plugin allow look the var like it appear?

  • @johnboy14
    @johnboy14 9 місяців тому

    The inclusion of generics has made me more interested in the language because support for polymorphism is a pretty key tool in alot of codebases I work on. Why it took so long to implement Generics in GoLang is a mystery to me.

  • @WiredMartian
    @WiredMartian Рік тому

    You've just changed my mind about Generics in Go!

  • @rumpeldrump
    @rumpeldrump 2 роки тому +1

    reinstall gopls with 1.18 to see the error on IDEs, which use it.

  • @dayanaracontreras4857
    @dayanaracontreras4857 Рік тому

    Goland is cool!@

  • @shinsanity6011
    @shinsanity6011 2 роки тому

    Is 1.18 production ready? I am using 1.17 on my working project but it on early stage, I want to switch version to 1.18 but I'm scare of reliability. Thank you

  • @JulioCesar-ym6by
    @JulioCesar-ym6by Рік тому

    I wonder, is the future of all newer languages ​​upgrading to the robustness of older languages? And we enjoy this "new" features 😅

  • @GreyDeathVaccine
    @GreyDeathVaccine Рік тому

    Insta sub - just for funny versions of go mascot.

  • @ThisAintMyGithub
    @ThisAintMyGithub 2 роки тому +1

    Great video! Also, if you don't mind me asking, what is your IDE theme?

  • @stephendelacruzone
    @stephendelacruzone 2 роки тому

    Dude... I sorta understand it as budding noobie-Golang-coder. But I have to re-watch it again when my knowledge and experience had matured. So Generics is how it handles, sorts any data types. Hmm... 🤔

  • @dominikvrbic7199
    @dominikvrbic7199 2 роки тому

    Are you going to update the cheat sheet with Generics?

  • @alltech9096
    @alltech9096 Рік тому

    How to add different generics to param 1 and 2

  • @baihuig
    @baihuig Рік тому

    really helpfull video! 只是,怪腔给怪调开门--怪到家了!

  • @jivy22
    @jivy22 2 роки тому

    Hey, great explanation on generics, thank you! Are you planning another Video with generics in combination with Interfaces? Just asking for a friend… 😉😉

    • @nobytes2
      @nobytes2 Рік тому

      he literally explained it on the video

  • @kishanbsh
    @kishanbsh Рік тому

    What about the "comparable" type ?

  • @gerardgauthier4876
    @gerardgauthier4876 2 роки тому +4

    I have to say, I doubt generics will make much of a difference in GoLang's popularity. GoLang is popular for a number of good reasons:
    1. Unicode(utf-8) out of the box.
    2. Simple to build.
    3. Interfaces. i.e. a simple object model.
    4. Concurrency.
    5. Memory safety.
    6. Higher order functions.
    7. Code that's not cluttered with boiler plate. Very clean and standard source code bc of enforced standard formatting.
    Generics might attract a few curious Java and C# programmers but I doubt they'll hang around long.
    I almost forgot... Sane IO and slices.

    • @michaelnajera7958
      @michaelnajera7958 2 роки тому

      Kotlin Rust Swift and many other modern languages have all those things you mentioned AND great generic systems. Is there anything else about Go?

    • @magicapyt
      @magicapyt 2 роки тому +1

      @@michaelnajera7958 Rust code is pretty much unreadble if you didnt invest a lot of time into lang. Swift/Kotlin has diffirent usecases atm. So I dont get your point

    • @michaelnajera7958
      @michaelnajera7958 2 роки тому +1

      “Rust code is pretty much unreadable”
      That’s just you’re opinion.
      “Kotlin/Swift have different use cases”
      Kotlin and Swift are general purpose languages just like Go or Python.
      You still haven’t answered my question. What more does the Go language give you that those other modern languages don’t?

  • @RobertWHurst
    @RobertWHurst 11 місяців тому

    Well kinda. You can't use them on struct methods which rules out about 60% of the use cases where I want to use generics.

  • @codelucky
    @codelucky Рік тому

    Goland vs VSC ?

  • @Haxory1
    @Haxory1 2 роки тому

    What IDE are you using?

  • @digvijayyamagekar4300
    @digvijayyamagekar4300 2 роки тому +1

    is this dubbed in english?

  • @gerardgauthier4876
    @gerardgauthier4876 2 роки тому +1

    (edit)Actually after a week to work through some, not so cute examples I have found a very workable generic pattern that works for even complicated generic types.
    Has anyone tried generics in Golang? I mean besides the cute examples! I can see this being the straw that broke the camel's back for some people trying GoLang. Talk about a half-assed approach to generics. Why would they produce such a terrible feature and then release it?
    I used generics in Java, C#, C++, OCaml, and several other languages and I've never come across such an odd implementation of generics... I think they should have stuck without generics.

  • @undochlorine
    @undochlorine Рік тому

    I'm beginner in Go, and I didn't know what generics is, but I heard everyone was looking forward to their releasing. Now I see and it looks like Go is losing it's tight types constraints and becomes TypeScript with their dope ANY, and everyone is happy about.... but it's awful, isn't it?

  • @anton4ik55
    @anton4ik55 2 роки тому

    So are you ripping off "Let's Get Rusty" style or is he ripping off yours?

  • @will_i_em
    @will_i_em 2 роки тому

    Generic types or Generics 🙄

  • @redcrafterlppa303
    @redcrafterlppa303 2 роки тому +11

    No front but I really can't understand why Go broke generics convention and used [ ] instead of . I don't care if is used in some other way but this looks unnatural and irritating for everyone coming from any other language. Many features differ between languages but for all languages I know generics are everywhere syntactically similar if not equal.

    • @normanklein3155
      @normanklein3155 2 роки тому +1

      yes, I agree with you completely. Just stupid arrogance on the part of Google and their engineers. Other than the concurrency parts, which are incredibly elegant, the rest of the Go language is quite ugly.

    • @thangnt2945
      @thangnt2945 2 роки тому +1

      Not to mention the error handling, like, is there something wrong with try-catch?

    • @redcrafterlppa303
      @redcrafterlppa303 2 роки тому

      @@thangnt2945 I don't know GO error handling and how good or bad it is. But this is a but different. Many languages differ in error handling. For example rust returns an combined type with result and error, or c stores error states globally. The point is that nearly every other language that supports generics and could have been a inspiration for GO generics uses . Using something different is just irritating and unnecessary complicated.

    • @nicogorr8440
      @nicogorr8440 Рік тому +1

      Because it would have required a breaking change:
      a, b := c < 10, d > 20
      These assignments have always been a totally valid Go code and, if you look carefully, you can see that they contain the conventially generics syntax (< , >) that would have broken the language lexer, if they had pursued the decision to go with it. That’s why they decided to go with the [] implementation.

    • @redcrafterlppa303
      @redcrafterlppa303 Рік тому

      @@nicogorr8440 is not a valid generic bound. Both could have used the < xxx > syntax. Besides there is a core context difference between:
      VARIABLE ASSIGNMENT CONDITIONS
      and
      TYPE_DEFINITION CONSTRAINT BODY
      You definitely don't quite fully understand how lexers work and what's a potential conflict and what isn't.

  • @torbilan6292
    @torbilan6292 Рік тому

    tried to listen for three minutes, content is great, but the accent is terrible

  • @samhanna7382
    @samhanna7382 2 роки тому +1

    go is inferior to rust