Supercharge Your Clients - The Functional Options Parameter Pattern in Go!

  Рет қаралды 1,040

TutorialEdge

TutorialEdge

6 ай бұрын

Howdy folks! In this video, we'll be looking at how you can supercharge your Go libraries using the functional options parameter pattern!
Site Link: tutorialedge.net/golang/funct...
👨‍💻 Sign up and gain access to a growing list of premium courses on my site - tutorialedge.net/pricing/
✅ Subscribe and hit that 🔔 to get notified for all the latest tutorials!
🤓 / elliot_f
‎💻 tutorialedge.net
📹 / tutorialedge
🎥 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

Пікірлер: 8
@baz_sh
@baz_sh 5 ай бұрын
Such an underrated channel. Really good practical examples.
@revdevkos
@revdevkos 6 ай бұрын
Isnt this just builder pattern? Make a function that returns the base value after modification.
@Tutorialedge
@Tutorialedge 6 ай бұрын
Thanks for your comment! I would say this is a variation of the builder pattern that's more focused on doing this as part of the initialisation of the struct within the constructor.
@revdevkos
@revdevkos 6 ай бұрын
​@@Tutorialedge Thanks for the info. I don't know GO and I randomly stumbled onto the video, but it all seemed so familiar to me. That being said, I have a lot of Java experience, and the builder pattern is very prevalent there. I have my own variation of the builder pattern. Basically, once you set up your standard getters and setters for a class, instead of having the setters return a void after they set the variable, they would return the class instance. example (might look weird in yt comments) public CustomClass setTitle(string title title){ this.title = title; return this; } What this allows you to do is chain commands when calling multiple setters. CustomClass custom = new CustomClass().setTitle("title").setValue("value").setRandomProp("random prop"); In "canonical" form this looks way uglier. CustomClass custom = new CustomClass(); custom.setTitle("title"); custom.setValue("value"): etc etc.. I don't know how "legal" this is, if there are any more implications under the hood, but I've never seen it being discussed anywhere as a possibility, and I find it more convenient than implementing the full builder pattern, while also abuses the autogeneration of classic setters, with just a minor modification, with the caveat that if you use build plugins (like Lombok for Java, that generates getters and setters on runtime), you'd still have to manually configure this setters. Sorry if it seems a bit random, but I hope it makes sense. I'd love to know if this is viable in GO and how it performs.
@Tutorialedge
@Tutorialedge 6 ай бұрын
It is certainly something you could do in Go. I've thrown a code snippet together here - go.dev/play/p/oQhq3mAU7Nn The Effective Go documentation does have some guidance on the user of getters and setters here - go.dev/doc/effective_go#Getters
@prashlovessamosa
@prashlovessamosa 6 ай бұрын
Wtf when the hell you came back i thought you forgot your YT password.
@Tutorialedge
@Tutorialedge 6 ай бұрын
I finally figured out there was a ‘1’ at the end of it after all this time!
@patrick_kabwe
@patrick_kabwe 6 ай бұрын
Good to have you back Elliot
Beginner's Guide to Redis with Go!
11:27
TutorialEdge
Рет қаралды 5 М.
Should You Learn Rust or Golang? #programming #shorts
0:42
Joining Error Values in Go with errors.Join
4:52
TutorialEdge
Рет қаралды 842
Who will win 🥇-  C++ vs Go language #cpp #cppprogramming #go #golang
0:22
Proto Coders Point
Рет қаралды 127 М.
C vs Python Speed Test #cpp #python #programming #code
0:25
Nicolai Nielsen
Рет қаралды 125 М.
My Wezterm Config
6:03
acklackl
Рет қаралды 949
Methods in Go - Beginner's Guide to Go Course
8:34
TutorialEdge
Рет қаралды 2,8 М.
3 SIMPLE Python Project Ideas
0:42
HitraN the Programmer
Рет қаралды 332 М.
How it feels writing your first program in C# versus python…
0:59
LeMaster Tech
Рет қаралды 161 М.