Golang: The Last Interface Explanation You'll Ever Need

  Рет қаралды 30,009

Flo Woelki

Flo Woelki

Күн бұрын

Пікірлер: 84
@rhysmuir
@rhysmuir 4 ай бұрын
When creating your interfaces, all this is easy to understand. It's when you are using imports (even from the standard library), is when it gets hard. There is no clear way to tell (that I'm aware of) what interface a stuct implements without digging through the code finding what functions an interface implements, and then checking if the struct you want to use implements those same ones
@seand7603
@seand7603 4 ай бұрын
It drives me nuts. Rust spoiled me :)
@kevinryan2992
@kevinryan2992 3 ай бұрын
The go language server (gopls) does implement this functionality, however I do agree if you are just reading code without the use of an external tool, implicit interfaces are definitely not as nice as explicit
@EHBRod13
@EHBRod13 9 күн бұрын
Implicit interfaces drove me away from Go. It made understanding the large code base at my old job really difficult.
@danielrosenthal7480
@danielrosenthal7480 5 ай бұрын
I've been struggling with how interfaces work for a while now and I think this video finally got it to click for me. Thank you.
@FloWoelki
@FloWoelki 5 ай бұрын
I am glad to hear that!
@sval4020
@sval4020 7 ай бұрын
Hey Flo, just wanted to say how much I like your teaching style. Your videos are great! Please cover more advanced Golang topics such as Go concurrency patterns and best practices. Thank you!
@FloWoelki
@FloWoelki 7 ай бұрын
Thank you so much for the great feedback! Go Concurrency patterns is definitely a video on my todo list :)
@davidmolizane
@davidmolizane 3 ай бұрын
Bro everything in this video is amazing, the quality of the explanation, camera, audio and code examples, thanks for this excelente tutorial
@FloWoelki
@FloWoelki 3 ай бұрын
Thank you for your comment and for watching the video! Glad I could help you :)
@nanonkay5669
@nanonkay5669 6 ай бұрын
The kind of thinking of interfaces being a contract is not wrong, but kinda abstract. Think of an interface as a membership, named after whatever you decide to call your interface, in this case "Shape". For any struct/class that wants to have that membership, they have to implement the functions described in that interface, much like how you may want to meet certain criteria to have a gym membership. So for Circle and Rectangle, they have to implement all Shape functions/methods to have a Shape membership. This is convenient because perhaps there could be a function somewhere that only takes Shape members to operate on them (calculateArea), and if Circle and Rectangle are Shape members, that function can operate on either one of them
@FloWoelki
@FloWoelki 6 ай бұрын
That's also a nice way to see it, except that I can always have a membership of something without meeting any requirement or using the membership :D
@guru_tz
@guru_tz 2 ай бұрын
Damn man, that was a direct hit. So clear and tqsm
@user-oz4tb
@user-oz4tb 3 ай бұрын
Ahh, such a lovely explanation! Finally clicked for me how and why Error interface works!
@FloWoelki
@FloWoelki 3 ай бұрын
Nice to hear that! So awesome that you found it helpful :)
@楊宏-l6t
@楊宏-l6t 6 ай бұрын
This teacher is so logical, thanks!!
@FloWoelki
@FloWoelki 6 ай бұрын
Thank you :D
@khaliddaoud
@khaliddaoud 2 ай бұрын
I'm new to Go and your video's help me a lot, thanks 🙏. Keep it up 💪
@FloWoelki
@FloWoelki 2 ай бұрын
Glad to hear it! Thank you so much :)
@SunilShahu17
@SunilShahu17 4 ай бұрын
Why don't we embed interface into structures? For example, If you intend to make a structure implement an interface, simply add "implement interface_name" in structure definition. That will add clarity in code. Right?
@yinetoyi
@yinetoyi 5 ай бұрын
Thanks for the video, the explanations are easy to understand. One thing I didn't fully get is how by passing the CalculationError{msg: "Invalid input"} struct instance on the performCalculation() the performCalculation() would use the Error() method of the CalculationError struct, I would've thought that we would need to call the Error() method of the struct but this is not the case, so what I gather with this is that the compiler implicitly deduces that since we are returning a value of type error and because we're using the CalculationError{msg: "Invalid input value"} struct instance as its return value it "sees" that this struct instance has a method that implements the Error() function and hence it uses it. So this is some sort of implicit default method for specific type returns or something like that, I honestly don't no how to refer to this behavior, I had no knowledge if this behavior but is good to know. Thanks again for putting this video together.
@codingchannel6263
@codingchannel6263 3 ай бұрын
error interface is already defined in Go's standard library. We don't need to define it ourselves; we only need to implement it. We don't need to write err.Error() explicitly. when we do fmt.Printf(error instance/objects of error struct ) In most cases, you don't need to call the Error() method explicitly. Go will call it automatically in certain situations: When you use fmt.Println() or fmt.Printf() with an error value. When you convert an error to a string (e.g., with err.Error() or string(err)).
@anuragraut5101
@anuragraut5101 19 күн бұрын
5:00 , you said if you added a new method in the shape interface , then the rectangle interface no longer implements it. That is in order for a struct to implement the interface it should implement all the methods of that interface . But Go interfaces are loosely coupled right ?a struct can implement part of the interface . I tried out the code to confirm it and the code still works . Am i interpreting it wrong or missing something here?
@MuhammadFahreza
@MuhammadFahreza 4 күн бұрын
Nice video, I was wondering what is the theme and IDE? it looks way more cleaner that my typical Goland. Thanks in advance!
@perajarac
@perajarac 2 күн бұрын
Great video!
@FloWoelki
@FloWoelki Күн бұрын
Thank you, and glad you enjoyed it! :)
@meka4996
@meka4996 27 күн бұрын
Amazing! Thank you
@cacadu971
@cacadu971 5 ай бұрын
I've never seen someone explain something that clearly
@FloWoelki
@FloWoelki 5 ай бұрын
Wow, thank you! :)
@chrisritter9344
@chrisritter9344 6 ай бұрын
This was great!
@FloWoelki
@FloWoelki 6 ай бұрын
I am glad you've liked it :)
@adigunolamide3230
@adigunolamide3230 5 ай бұрын
Your videos are amazing.
@FloWoelki
@FloWoelki 5 ай бұрын
Thank you so much! :)
@donzepe
@donzepe 6 ай бұрын
Nice explanation my friend!
@FloWoelki
@FloWoelki 6 ай бұрын
Thank you! Cheers!
@melihdev
@melihdev 3 ай бұрын
Can you explain the layered architecture in go?
@himanshubanerji8800
@himanshubanerji8800 Ай бұрын
I want to go back to Java already, this Go gets more and more complex as I learn
@costathoughts
@costathoughts 2 күн бұрын
I really look Go as an easy and readable language, because once you have touch with OOP, Aspect, and other suff famous on java world everything is possible to overcome
@rakeshfalak5118
@rakeshfalak5118 5 күн бұрын
Awesome!
@karlrichardson7548
@karlrichardson7548 5 ай бұрын
Thanks This helped a lot.
@FloWoelki
@FloWoelki 5 ай бұрын
I am glad it helped :)
@falanges5301
@falanges5301 6 ай бұрын
Thanks so much 💝 this really helped me, keep on goin
@FloWoelki
@FloWoelki 6 ай бұрын
You're welcome 😊
@anon_y_mousse
@anon_y_mousse 5 ай бұрын
As far as I've understood it, they're basically like a class in C++ where everything is virtual. Generally we'd refer to that as an abstract class. That and error codes instead of exceptions I copied as features for my own language. I don't like that they use it as a sort of replacement for genericity syntax though. It's basically another void pointer, but with the requirements for casting turned 180 degrees. So better, but not good enough in my opinion. Looks like you do both Rust and Go, but perhaps you should add more languages to your repertoire like plain C and demonstrate how different constructs work at a fundamental level by converting them to C.
@sammyj29
@sammyj29 4 ай бұрын
Great stuff! Subbed
@FloWoelki
@FloWoelki 4 ай бұрын
Much appreciated! :)
@nullPointer0x0
@nullPointer0x0 7 ай бұрын
Nice explanation. Thanks. Subscribed.
@FloWoelki
@FloWoelki 7 ай бұрын
Awesome, thank you!
@nikital2608
@nikital2608 6 ай бұрын
What is the font name?
@FloWoelki
@FloWoelki 6 ай бұрын
I am using `monaspace` :)
@tiagodev5838
@tiagodev5838 5 ай бұрын
I knew I could rely on this already being asked 😂
@pradeepram8458
@pradeepram8458 Ай бұрын
i tried the different fonts in the monaspace family - like Neon, Xenon - nothing comes close to how thin it looks on your screen/editor
@jeromelanteri321
@jeromelanteri321 5 ай бұрын
Nice video, but on the language accordance with logic of interface design, let's said that a Shape has a perimeter. So it does reduce the understand about what is the idea to implement a new interface to any duty contract. I would better think about Position as a new interface. Because a shape will have any area, perimeter by logic. But the position it can have is not due to the fact it is a shape, but because this shape can be somewhere. So, for example, An interface named Object can be the resulted union about Shape and Position. This (in my mind) is the way to think about contract interface in Golang (and most probably, in interface in general). Tell me if you are ok with this observation, please.
@karthikm.1804
@karthikm.1804 5 ай бұрын
Nice explanation, please bring video on golang projects too
@FloWoelki
@FloWoelki 5 ай бұрын
Thank you! I'll try my best :)
@KaustubhDeokar
@KaustubhDeokar 3 ай бұрын
thank you so much
@FloWoelki
@FloWoelki 3 ай бұрын
Glad I could help you :)
@joselima7655
@joselima7655 5 ай бұрын
Very nice! Thank you +sub
@FloWoelki
@FloWoelki 5 ай бұрын
Thank you! :)
@vishamr2012
@vishamr2012 6 ай бұрын
excellent..Thx a lot
@FloWoelki
@FloWoelki 6 ай бұрын
Thank you for watching :)
@maguilecutty
@maguilecutty 3 ай бұрын
The shape interface is the same explanation everywhere. Why can’t someone make a video with thing we would actually use so the real world usage would make sense
@zero_charge
@zero_charge 2 ай бұрын
Because of the unoriginality of our era. What get's me though is when I watch a video with a title like this one which says that you are not going to need another tutorial and then proceeds to copy the same examples and same way of presenting the information from other videos.
@FloWoelki
@FloWoelki 2 ай бұрын
Thank you both for the valuable feedback! Do you know how to showcase the concepts in a more real-world use case? I am currently experimenting with different videos with simple projects (like a text analyzer) to apply the learned concept at the end of the video.
@maguilecutty
@maguilecutty 2 ай бұрын
@@FloWoelki Think of something you impliment everyday. Im writing GRPC microservices everyday, creating factories, builder models etc. Maybe just a simple user database writer? Also, something that REALLY GETS MY GOAT (can you tell?) is that every dev on yt just writes a main.go file. Dont be lazy and actually impliment the hex model like you would write an actual service and show how it all works together. This will be INVALUABLE to new devs learnign go!
@saifmohammed1481
@saifmohammed1481 2 ай бұрын
Unless im missing something, its Honestly a bad design by Go designers. How would I know what interfaces a type implements off the bat ?
@FloWoelki
@FloWoelki 2 ай бұрын
You are not missing anything! I personally also think that it is not always 100% clear if a struct uses a specific interface. I like more the explicit design, like in other languages.
@nyvy-z8t
@nyvy-z8t Ай бұрын
honestly speaking, i am still not convinced as to why are we doing all this, by watching this video. Simple example is understood, but in practical terms what it is solving is still unknown
@meryplays8952
@meryplays8952 3 ай бұрын
Does not cover type constraints. For example type Likeint interface {~int}
@inifitecosmos
@inifitecosmos 6 ай бұрын
👌
@AbhinavNair-x8t
@AbhinavNair-x8t 4 ай бұрын
ur explanation is very good but please change the background music. I makes us sleepy
@FloWoelki
@FloWoelki 4 ай бұрын
Well, it's kind of a vibe :D It should be relaxing and enjoyable to watch the video. Usually, I just have some music at the beginning and at the end of the video.
@atljBoss
@atljBoss 6 ай бұрын
implicit implementation of interfaces is a bit weird in Go. Would prefer the rusty way!
@FloWoelki
@FloWoelki 6 ай бұрын
I prefer the explicit interface implementation as well, because things are much clearer.
@jordanhasgul4401
@jordanhasgul4401 6 ай бұрын
If you want to make it clear that a struct implements a particular interface, you can do a compile time assertion. var _ MyInterface = (*MyStruct)(nil) So you get the explicitness while still allowing consumers to define their own interfaces for which your struct can also satisfy. Not saying to do this, just sharing some knowledge.
@atljBoss
@atljBoss 5 ай бұрын
@@jordanhasgul4401 Damm didn't know this, thanks!
@albizutoday2754
@albizutoday2754 3 ай бұрын
Is Rust gay?
@zero_charge
@zero_charge 2 ай бұрын
Yes. I heard it is
@dixztube
@dixztube 4 ай бұрын
Took me a good year before it just for some reason made sense lol now it’s like oh ya I get but the explanations are ugh idk I don’t like the contract explanation
@pookiepats
@pookiepats Ай бұрын
Cant learn from watching somebody, teachers would do well to generate written lessons or just classify as entertainment but there is no middle ground. So much time is wasted “learning” from videos
@zalaam_0
@zalaam_0 Ай бұрын
You look like magnus
@FloWoelki
@FloWoelki Ай бұрын
Well, I've never heard that before :D
DIY Golang Web Server: No Dependencies Needed!
25:04
Flo Woelki
Рет қаралды 15 М.
Level Up Your Golang: 5 Concepts You Need to know
19:22
Flo Woelki
Рет қаралды 16 М.
Война Семей - ВСЕ СЕРИИ, 1 сезон (серии 1-20)
7:40:31
Семейные Сериалы
Рет қаралды 1,6 МЛН
Wednesday VS Enid: Who is The Best Mommy? #shorts
0:14
Troom Oki Toki
Рет қаралды 50 МЛН
#behindthescenes @CrissaJackson
0:11
Happy Kelli
Рет қаралды 27 МЛН
This is your last video about Golang Structs!
15:57
Flo Woelki
Рет қаралды 13 М.
A Practical Example How To Use Interfaces In Golang
14:42
Anthony GG
Рет қаралды 31 М.
Why #Go Interfaces? / #Golang Interfaces Tutorial
9:41
defer panic
Рет қаралды 40 М.
Zig For the Uninitiated: Zig Interfaces
11:56
Tyler Calder
Рет қаралды 4,3 М.
Testing WITHOUT Mocks or Interfaces!
12:27
CodeOpinion
Рет қаралды 25 М.
Always Use Interfaces
8:08
Christopher Okhravi
Рет қаралды 50 М.
Advanced Golang: Channels, Context and Interfaces Explained
22:17
Code With Ryan
Рет қаралды 129 М.
Master Golang with Interfaces
21:54
Kantan Coding
Рет қаралды 20 М.
The Must pattern in Golang clearly explained!
15:13
Flo Woelki
Рет қаралды 8 М.
Building Real-time Apps with Go | Azim Pulat
54:58
Azim Pulat
Рет қаралды 104 М.