Why Golang's IO.READER Is More Important Than You Think

  Рет қаралды 11,795

Anthony GG

Anthony GG

Ай бұрын

► Join my Discord community for free education 👉 / discord
► Exclusive Lessons, Mentorship, And Videos 👉 / anthonygg_
► 33% OFF on my Go + HTMX + Templ Course PRESALE 👉bit.ly/3UFruxO
► Enjoy a 60% Black Friday 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
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Пікірлер: 62
@anthonygg_
@anthonygg_ Ай бұрын
► 33% OFF on my Go + HTMX + Templ Course PRESALE bit.ly/3UFruxO ► Join my Discord community for free education discord.com/invite/Ac7CWREe58 ► Exclusive Lessons, Mentorship, And Videos www.patreon.com/anthonygg_ ► 60% OFF on my Golang course fulltimegodev.com Thanks for watching
@makesnosense6304
@makesnosense6304 Ай бұрын
It's the difference between specifying the type of data needed vs specifying something that implements functionality needed. If you do []byte you are saying you only take this type of data. If you do io.Reader you are saying you take anything that implements what that interface is implementing. In this case anything that implements a function with the following structure: Read(p []byte) (n int, err error) This means that any struct that has that function can be used. Which means greater flexibility and nicer code. It also means it's easy to mock and test. It also means that each implementation can get the data however it wants. It can be from memory, from storage, from internet. When using an interface like this it doesn't matter where it's coming from. It's just stating what it wants.
@anthonygg_
@anthonygg_ Ай бұрын
Makes sense 🫡
@GlennLewis
@GlennLewis Ай бұрын
Another practical example is when you need to inject a gzip encoder/decoder and/or base64 encoder/decoder into your stream... with an io.Reader it is pretty trivial. Great video... thanks for sharing!
@Sanjay-iy5zf
@Sanjay-iy5zf Ай бұрын
Just finished watching "7 Common mistakes in Go and When to avoid them" by Steve Francia (spf13) where he mentioned the same and GG posted a new detailed video on that. Well, I'm impressed
@yusufcansert9276
@yusufcansert9276 Ай бұрын
Slice is a pointer, we are using interface so it can be used with other types
@yusufcansert9276
@yusufcansert9276 Ай бұрын
I am not sure, if this video is ok
@fsync_off
@fsync_off Ай бұрын
Because having an interface is better than a concrete type of data - it's much harder to break/violate contract defining interoperability between different parts of software later. Future you using the lib you write today will be grateful.
@comfortcove
@comfortcove Ай бұрын
Love your go videos - really helpful to create mental map of language native tools. BTW. glad to see you sticking with nvim after configuration session.
@carylandholt
@carylandholt Ай бұрын
This was excellent! Really helped me understand the use cases for readers and writers in go. Thank you!
@kevinb1594
@kevinb1594 Ай бұрын
Demonstrating the memory footprint of both approaches would have been better than just telling us this is how it is.
@ThePandaGuitar
@ThePandaGuitar Ай бұрын
This video is gold. More of these Go nuggets in short format
@tranquangthang8897
@tranquangthang8897 Ай бұрын
Oh Anthony on neovim setup let's go
@goliy1
@goliy1 Ай бұрын
Just today I thought he is the only one (who I’ve been watching) uses vscode and voila - not anymore 😂
@matiasbpg
@matiasbpg Ай бұрын
Already vimming like a pro ❤! I think it's time to introduce more w and b to move horizontally. Great video BTW, really like your content, would love to have time to watch your longer videos
@canoozie
@canoozie Ай бұрын
Nice. Also, one tip, neovim related; you struggled getting back to your original file (the one you gd'd on); but one thing you can do, is set up a keybind that calls: :b#
@anthonygg_
@anthonygg_ Ай бұрын
Thanks for that
@kavy6114
@kavy6114 Ай бұрын
This guy deserves more views
@anthonygg_
@anthonygg_ Ай бұрын
We agree here 😅
@t1m3__
@t1m3__ Ай бұрын
Great explanation, thanks!
@furyfuryfury
@furyfuryfury 20 күн бұрын
Hey, Anthony! Thank you very much for your videos. They are very interesting and useful. You're doing a great job. Can you tell me which text editor do you use (I assume that this is one of the varieties of Vim)? Could you share your configuration config (I'm especially interested in how you implemented code completion for Golang)?
@dranon0o
@dranon0o Ай бұрын
It's an excellent one and i'm fighting at work to make new comers in the language to understand composability and especially that topic
@natterbrot
@natterbrot Ай бұрын
I‘ll be honest, I usually do, but I didn‘t like your explanation here. Way too fast. I think your point could‘ve been clearer if you actually kept using the bytes for longer so the viewer actually sees when that approach falls apart. Thanks otherwise and keep up the work!
@anthonygg_
@anthonygg_ Ай бұрын
100 % agree. The problem is that people will slip away from the vid and call me a yapper. Trying to find the sweet spot
@makesnosense6304
@makesnosense6304 Ай бұрын
It's the difference between specifying the type of data needed vs specifying something that implements functionality needed. If you do []byte you are saying you only take this type of data. If you do io.Reader you are saying you take anything that implements what that interface is implementing. In this case anything that implements a function with the following structure: Read(p []byte) (n int, err error) This means that any struct that has that function can be used. Which means greater flexibility and nicer code. It also means it's easy to mock and test. It also means that each implementation can get the data however it wants. It can be from memory, from storage, from internet. When using an interface like this it doesn't matter where it's coming from. It's just stating what it wants. And in this case it can also be streamed data.
@iCrimzon
@iCrimzon Ай бұрын
​@@anthonygg_ i dont think you should worry about being called a yapper, the whole point is to teach us new methods/stuff, if the brainrot viewers cant focus then thats their problem
@demmidemmi
@demmidemmi Ай бұрын
​@@anthonygg_ the biggest point missing for my Timmy brain is that slices are passed as pointers so the memory usage is the same in both examples. Maybe us Timmies need a longer form video on how to not ReadAll and pass io. Readers instead.
@-mau
@-mau Ай бұрын
neovim gigachad
@arnoldwolfstein
@arnoldwolfstein Ай бұрын
Thanks man.
@grim.reaper
@grim.reaper Ай бұрын
io.Reader is the GOAT in GoLang
@nexovec
@nexovec Ай бұрын
It's not true that other languages don't heavily use reader/writer, I vividly remember dealing with them like 8 years ago in java or something. It's not actually true what some people think, that the bytes would get copied each time you pass the byte slice somewhere, since the slice itself is just a pointer with some metadata.
@anthonygg_
@anthonygg_ Ай бұрын
Not if you read from a connection man.
@nexovec
@nexovec Ай бұрын
@@anthonygg_ My chatbot spat out code for a tcp reader in java just fine, wdym, explain.
@kevinz1991
@kevinz1991 Ай бұрын
great video thank u
@lev2590
@lev2590 Ай бұрын
Audio compression hitting hard in this video
@anthonygg_
@anthonygg_ Ай бұрын
Struggling with audio since day 1
@nf-racing71
@nf-racing71 Ай бұрын
I would have loved a more detailed, slow explanation, assuming we know less. Because people that already know and understand won't click anyways. I liked it tho!
@zexzinc5138
@zexzinc5138 Ай бұрын
Why not a pointer?
@anthonygg_
@anthonygg_ Ай бұрын
Doesnt hook into third parties and std functions
@Yoshidzo
@Yoshidzo Ай бұрын
Slice is basically a pointer + length already
@erikslorenz
@erikslorenz Ай бұрын
io reader and writer are the best things ever
@eddymoreno5624
@eddymoreno5624 Ай бұрын
Hello,Where can i find some Remote entry jobs in golang?
@kruczek1986
@kruczek1986 Ай бұрын
i always watch you video with pleasuere, and what be sure that i understand what you say and correct me if i am wrong, but effectiveness of the solution, i mean using io.Reader depend on what implementation we use, correct? i mean how we will read this interface on the function where we have it pass...
@guitaripod
@guitaripod Ай бұрын
4k plz papi
@hautran7559
@hautran7559 Ай бұрын
Sorry but can anyone explain why use []bytes that read all data from memory but io.Reader does not do that
@GoWithAndy-cp8tz
@GoWithAndy-cp8tz Ай бұрын
The sentence you provided has some minor grammatical errors. Here's a corrected version: "Please check if this sentence is proper English. Could you give me a hint on how to organize an IDE to quickly access functions' definitions and documentation like I do? Cheers! So far, I've been using VS Code, but I can see you use something more like Vim. Am I completely wrong?"
@manee427
@manee427 Ай бұрын
amazing
@prescientdove
@prescientdove Ай бұрын
please install a nerd font or use the devicons bro, it makes me sad to see those question marks on your tabs :(
@wvdeventer
@wvdeventer Ай бұрын
Neovim by the way
@agent_ly
@agent_ly Ай бұрын
I love your content but I don’t think this video actually tells us why to use io.Reader over raw dogging a byte slice aside from the std always using it. I wish you went more in-depth about how it would be copying the whole slice into memory and how strict you should be when it comes to using it. For example do I need an io.Reader if I’m parsing a RESP message or any other simple byte structure?
@kevinb1594
@kevinb1594 Ай бұрын
He literally says you'd be copying the whole byte array into memory at once instead of parts by not using a reader.... Like 6 times.
@agent_ly
@agent_ly Ай бұрын
@@kevinb1594 no i get that, but at what point is it a bad thing? What if my bytes don’t need to be chinked?
@tokoucin
@tokoucin Ай бұрын
If reason here just avoid copying, why not just using pointer there.
@anthonygg_
@anthonygg_ Ай бұрын
The reason is the opt in with other libs not only the mem
@mohamedoussous7242
@mohamedoussous7242 Ай бұрын
copying isn't a problem here (btw slices are not pass by value, they work just like pointers). it's that you load all the data at ONCE, even if you use pointer you still have to allocate memory for all the data. and this is what Reader fixes, it loads the data in CHUNKS.
@anthonygg_
@anthonygg_ Ай бұрын
I thought I literaly mentioned, 1. Third party and std use readers all the time. 2. Reads in chunks.
@makesnosense6304
@makesnosense6304 Ай бұрын
It's the difference between specifying the type of data needed vs specifying something that implements functionality needed. If you do []byte you are saying you only take this type of data. If you do io.Reader you are saying you take anything that implements what that interface is implementing. In this case anything that implements a function with the following structure: Read(p []byte) (n int, err error) This means that any struct that has that function can be used. Which means greater flexibility and nicer code. It also means it's easy to mock and test.
@anarrzayev1366
@anarrzayev1366 15 күн бұрын
let's say it makes our function more generic, more dynamic... or more `goish` :)
@pacman777
@pacman777 Ай бұрын
No
@chudchadanstud
@chudchadanstud Ай бұрын
The absolute state? I think I'll just stick to C and Rust. Pass it by reference and use slices. Problem solved.
This Will Make Everyone Understand Golang Interfaces
21:03
Anthony GG
Рет қаралды 42 М.
3 Important Use Cases Why The Industry Is Using Kafka
7:52
Anthony GG
Рет қаралды 12 М.
1🥺🎉 #thankyou
00:29
はじめしゃちょー(hajime)
Рет қаралды 81 МЛН
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 14 МЛН
The Hidden Cost Of GraphQL And NodeJS
28:35
ThePrimeTime
Рет қаралды 182 М.
The standard library now has all you need for advanced routing in Go.
13:52
SQLite is enough
5:58
Martin Baun
Рет қаралды 8 М.
A Practical Example How To Use Interfaces In Golang
14:42
Anthony GG
Рет қаралды 18 М.
Don't Make this Golang Beginner Mistake!
8:57
Anthony GG
Рет қаралды 17 М.
The BEST Tool to Structure Golang Projects
7:58
Melkey
Рет қаралды 16 М.
Mastering Inheritance By Struct Embedding In Golang
13:05
Anthony GG
Рет қаралды 28 М.
Beginners Should Think Differently When Writing Golang
11:35
Anthony GG
Рет қаралды 93 М.
Object Oriented Programming is Good | Prime Reacts
31:30
ThePrimeTime
Рет қаралды 285 М.
1🥺🎉 #thankyou
00:29
はじめしゃちょー(hajime)
Рет қаралды 81 МЛН