Getting Started with Generics in Go

  Рет қаралды 27,980

TutorialEdge

TutorialEdge

Күн бұрын

👨‍💻 For the price of $7.99 every month, sign up and gain access to a growing list of premium courses on my site - tutorialedge.net/pricing/
Welcome Gophers, in this video, we'll be covering the topic of generics in Go! We'll be covering the basic syntax and also moving on to some more in-depth examples which demonstrate the value generics bring to the Go development community!
The original article can be found here - tutorialedge.net/golang/getti...
✅ Subscribe and hit that 🔔 to get notified for all the latest tutorials!
🤓 / elliot_f
‎💻 tutorialedge.net
🎥 Recording Setup
Microphone - amzn.to/3hvASys
Mic Boom - amzn.to/3o0cW8Q
Mouse - amzn.to/2WZMoZs
Monitor 1 - amzn.to/38IUlYy
Monitor 2 - amzn.to/3rBTZf7
Mount - amzn.to/3o3185V
USB-C Hub - amzn.to/3o2xRbw

Пікірлер: 33
@necroowl3953
@necroowl3953 2 жыл бұрын
I honestly waited for you to explain how these would be useful in Go. I am not disappointed once again, and you did a great job explaining it with a practical example. I want to add that it is important to underline that Generics in Go can only be applied when the logic is exactly the same. Otherwise it is always best to type check the inputs via an empty interface (where specific types follow specific logic). One example is JSON marshaling, which cannot be implemented using generics. Thanks for this video, and cheers for giving clarity on this topic.
@capythulhu
@capythulhu 2 жыл бұрын
Generics aren't alternatives to type checking, they work well together. If you were implementing a Power function without generics, for example, you would have to create two functions for numbers in general: floatPower(n float64) and intPower(n int64). If you wanted to make it possible for types of every size, you'd have to create even more functions such as: float32Power(n float32), int8Power(n int8), etc. Or, you could use the empty interface approach, but you would have to treat cases such as power("hello"). That means you would have to either have the possibility of a unexpected behavior or you would have to return an error, so you'd have to check that error _every single time_ you call that function just because it is syntactically possible for the user to send something that's not a number into your function. With Go generics, you can just have a func power[num int8 | int16 | int32 | int64 | float32 | float64](n num) and still perform the type check for different operations, if that's the case.
@ravi-mo6js
@ravi-mo6js 2 жыл бұрын
Eeeeexcellent, said Mr. Burns xD
@oussamasethoum1665
@oussamasethoum1665 2 жыл бұрын
One of the best things you can do a video on is entgo + gqlgen for full backend with graphql
@angrysmilex
@angrysmilex 2 жыл бұрын
Very clear explanation, thanks!
@mumk
@mumk 2 жыл бұрын
Thanks a lot for the sharing
@sultansheikh6184
@sultansheikh6184 Жыл бұрын
One of the best channel for go keep up bro 💪
@Somethingsomethinglol
@Somethingsomethinglol Жыл бұрын
Great explanation ty
@javisartdesign
@javisartdesign 2 жыл бұрын
Awesome, I think it `s something to expect in a language these days. Since you cannot cast the value anymore if you use any, you cannot create a generic list to store interfaces, string, numbers, etc.. and then extract the values to continue working with them?
@codelinx
@codelinx Жыл бұрын
Amazing content and explanations.
@mirabbos02
@mirabbos02 2 жыл бұрын
Cool 👍
@ThanhNguyen-kt8kj
@ThanhNguyen-kt8kj 2 жыл бұрын
What is the theme you use for vscode? Thank you so much.
@3r1c3
@3r1c3 2 жыл бұрын
Can someone plz tell me the name of this vscode theme? I love it
@MichalKoziatek
@MichalKoziatek 2 жыл бұрын
same! Really nice colours
@am_0x2a
@am_0x2a Жыл бұрын
What sweet VS Code theme is that?!
@user-ed4pz1yu8b
@user-ed4pz1yu8b 2 жыл бұрын
Hi! What colorscheme do you use?
@usernameL1
@usernameL1 2 жыл бұрын
Would like to know as well!
@hidayathidayat4469
@hidayathidayat4469 2 жыл бұрын
hallo everyone. how people implement this without generic?
@LopestEmarq
@LopestEmarq Жыл бұрын
One function for each type (and yes, some code repetition)
@mwat56
@mwat56 2 жыл бұрын
Why do I always hear "genetic" (instead of "generic")?
@katzenschildkroete
@katzenschildkroete 2 жыл бұрын
Ouelsh Akksent
@JonathanLoscalzo
@JonathanLoscalzo 2 жыл бұрын
Google translate too
@ScottKFraley
@ScottKFraley 2 жыл бұрын
Probably the Scotish accent. :)
@shuaibolayinka7644
@shuaibolayinka7644 2 жыл бұрын
doest this work for custom types?
@Max-bh8tg
@Max-bh8tg 2 жыл бұрын
Yes it does
@champfisk5613
@champfisk5613 2 жыл бұрын
This is nice but I will wait for it to be released in stable
@Max-bh8tg
@Max-bh8tg 2 жыл бұрын
It's been released now!
@williamokano
@williamokano 2 жыл бұрын
Seems more like union types than generics itself
@Max-bh8tg
@Max-bh8tg 2 жыл бұрын
Using the "any" keyword will make it totally generic.
@williamokano
@williamokano 2 жыл бұрын
@@Max-bh8tg 😂
@TroenderTass
@TroenderTass 2 жыл бұрын
Well, i've got to say they finally gave people a reason to maybe use go. Up to now, the language has been completly useless
Beginner's Guide to Unit Test Logging in Go
3:55
TutorialEdge
Рет қаралды 1,1 М.
Golang Generics. Do we ACTUALLY need them!?
12:51
Golang Dojo
Рет қаралды 19 М.
No empty
00:35
Mamasoboliha
Рет қаралды 9 МЛН
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 37 МЛН
Understanding Contexts in Go in 5(-ish?) Minutes
15:14
TutorialEdge
Рет қаралды 60 М.
Golang generics in 6 minutes
6:51
Cloud Native Skunkworks
Рет қаралды 12 М.
Golang Performance Hack That Reduces GC Overhead
15:42
Anthony GG
Рет қаралды 16 М.
Golang Channels Or Wait Groups? Let Me Explain.
18:32
Anthony GG
Рет қаралды 20 М.
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 169 М.
The Most Legendary Programmers Of All Time
11:49
Aaron Jack
Рет қаралды 542 М.
What can you build in Golang?!
11:10
Golang Dojo
Рет қаралды 166 М.
Tutorial: Do you really think you understand Go interfaces?
11:38
Learn Go Programming
Рет қаралды 65 М.
Generics Unconstrained! - Roger Peppe
28:31
GopherCon UK
Рет қаралды 4,6 М.
the end 😂🤣 #funny #funnyshorts #funnyfails #failsvideo
0:52
Purr Laughs
Рет қаралды 14 МЛН
小路飞跟姐姐去哪里了#海贼王#路飞
0:45
路飞与唐舞桐
Рет қаралды 46 МЛН
@juanchinbrodie #comedia #humor #juffec #felipecharry #amigos
0:15
Felipe Charry
Рет қаралды 5 МЛН