Тёмный

The Power Of Struct Embedding And Interfaces In Golang 

Anthony GG
Подписаться 59 тыс.
Просмотров 14 тыс.
50% 1

► Join my Discord community for free education 👉 / discord
► Exclusive Lessons, Mentorship, And Videos 👉 / anthonygg_
► Enjoy a 50% Discount on My Golang Course 👉 fulltimegodev.com
► Learn how I became a self-taught software engineer 👉fulltimegodev.com/#mystory
► Follow me on Twitter 👉 / anthdm
► Follow me on GitHub 👉 github.com/anthdm
SUBSCRIBE OR NO MARGARITAS
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Опубликовано:

 

2 сен 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 26   
@anthonygg_
@anthonygg_ 10 месяцев назад
► Join my Discord community for free education 👉 discord.com/invite/Ac7CWREe58 ► Exclusive Lessons, Mentorship, And Videos 👉 www.patreon.com/anthonygg_ ► 50% OFF on my Golang course 👉 fulltimegodev.com Thanks for watching
@anshkumargarhewal8582
@anshkumargarhewal8582 10 месяцев назад
Another very informative video thanks anthony and congrats for 20k Subs.🎉
@_Kntch
@_Kntch 10 месяцев назад
Great video as always 💪🏽💪🏽🔥🔥
@stephanschmidt2334
@stephanschmidt2334 7 месяцев назад
Love your videos
@anthonygg_
@anthonygg_ 7 месяцев назад
Ty
@xseman
@xseman 3 месяца назад
some diagram visualization would help to understand this example
@bl2575
@bl2575 10 месяцев назад
My problem with golang implicit interface is how do you figure out what function can be used with a type? The standard library doc (AFAIK) doesn't provide a list of functions that can be used with each struct type, which make it difficult to figure out what you can do with it...
@Jarek.
@Jarek. 6 месяцев назад
This is actually a very good question. Till now I haven't found any better way than just running an instance of godoc locally (with -index option) and just search there. But happy to hear any better solution. Cheers 👍
@susiebaka3388
@susiebaka3388 5 месяцев назад
@@Jarek. i am a new golang user, do you have a chance to explain a bit more how i can use godoc to accomplish this?
@ForeverZer0
@ForeverZer0 10 месяцев назад
I am still a bit new to Go, coming from a C background, so my apologies if this is a stupid question, but what is the purpose of the embedded "base" struct being a reference instead of a value? Does this alter any of the semantics for how the interfaces or "inherited" (for lack of a better word) functions work? Otherwise wouldn't this simply increase the chances of a nil reference and fragment memory, leading to more cache misses?
@anthonygg_
@anthonygg_ 10 месяцев назад
At this point of the example a pointer to Enemy is not needed. But, if Enemy is no pointer and you want to modify the underlying transform, called in another function you will modify a copy. But your point on fragmentation and cache misses is valid.
@ForeverZer0
@ForeverZer0 10 месяцев назад
@@anthonygg_ Ah yes, I did not think of that aspect of it. I have gotten into the habit of always using reference receivers over value ones when writing functions which alleviates that, but obviously is not always possible or the desired behavior for every scenario. I have noticed there are some "gotchas" with embedded structs. The syntatic sugar makes it easy to view it as inheritance, which can lead to shooting yourself in the foot. My first sincere effort at a Go project required a major overhaul because I wrongfully assumed I could cast the "base" type into the type calling the function. This broke my habit of naming the receiver "self" or "this" lol.
@kanfit
@kanfit 9 месяцев назад
hei Anthony, I am just wondering what design parttern should be called for this enbedded struct and interface?
@xseman
@xseman 3 месяца назад
I'd say it's just polymorphism, not a specific pattern, just a specific implementation
@joshi1q2w3e
@joshi1q2w3e 10 месяцев назад
So in this case, are objects like Enemy, Transform, and FireEnemy, like classes in Python? Coming from Python I’m having a hard time understanding how to write Go code because it doesn’t use Classes.
@functionator
@functionator 10 месяцев назад
Think of them as dictionary objects instead. Embedding is similar to composing dictionaries so you can reference the embedded attributes directly
@anthonygg_
@anthonygg_ 10 месяцев назад
Correct.
@joshi1q2w3e
@joshi1q2w3e 10 месяцев назад
@@anthonygg_ just to clarify were you saying correct to my statement or to @functionator?
@anthonygg_
@anthonygg_ 10 месяцев назад
@@joshi1q2w3e @functionater is kinda right here. You need to think about structs as pieces that hold data. If you embed piece A into piece B. B will have the fields of piece A
@jaysaha1967
@jaysaha1967 10 месяцев назад
Go is a complete procedure language so comparing with OOPS of python is not really wise.. but if you want to then classes of python is what would be replaced by gos struct
@MotivationVideos1337
@MotivationVideos1337 10 месяцев назад
Your discord link is dead
@anthonygg_
@anthonygg_ 10 месяцев назад
Thanks
@couragic
@couragic 10 месяцев назад
8:06 Why do you pronounce TileWalker as “TileWalkesh” ? Just curious
@anthonygg_
@anthonygg_ 10 месяцев назад
Because I make 30k a month
@Anonymous-js9vc
@Anonymous-js9vc 6 месяцев назад
what vscode theme is this ??
@Anonymous-js9vc
@Anonymous-js9vc 6 месяцев назад
found it Gruvbox Glass
Далее
Beginners Should Think Differently When Writing Golang
11:35
This Will Make Everyone Understand Golang Interfaces
21:03
НЕ ДЕЛАЙТЕ УКЛАДКИ В САЛОНАХ
00:43
Rope climb tutorial !! 😱😱
00:22
Просмотров 1,6 млн
Golang Channels Or Wait Groups? Let Me Explain.
18:32
Master Golang with Interfaces
21:54
Просмотров 7 тыс.
A Practical Example How To Use Interfaces In Golang
14:42
From React To HTMX
40:01
Просмотров 306 тыс.
This Is The BEST Way To Structure Your GO Projects
11:08
Object Oriented Programming is Good | Prime Reacts
31:30
Structs in golang
8:11
Просмотров 35 тыс.
Why I Use Golang In 2024
9:21
Просмотров 257 тыс.
How To Build A Custom TCP Server In Golang!?
19:32
Просмотров 24 тыс.
Go Pointers: When & How To Use Them Efficiently
14:09