DEV Community

Discussion on: 12 Personal Go Tricks That Transformed My Productivity

 
func25 profile image
Phuong Le

One thing I'd like to point out is that, you can use a single struct as an argument for a function with the "required" tag from the validator/v10 package. This approach is kinda handy for functions with numerous arguments.

Your hashtag #fwiw (for what it's worth) sums it up well. We all bring our unique experiences and biases to the table, and I appreciate you sharing yours.

Regarding my blog, thank you, Mike. I'm truly honored by your kind words. Feedback like yours motivates me to continue writing and sharing my insights with the community.

Thread Thread
 
mikeschinkel profile image
Mike Schinkel • Edited

Interesting idea about the "required" tag. I can see where that would be useful for ensuring that types have required values, although I do like to minimize dependencies so unless I felt the need to use a lot of its functionality I would likely still shy away.

OTOH, it would not be hard to implement a required tag of my own and not require a dependency, so thanks; that is something for me to consider.

As for args, I have used the strategy of positional required args and optional args as structs for over well more than a decade and across numerous languages and have found it to be easy to be consistent and have never found it to fail me, so I doubt I personally would want to change to using all parameters in structs.

I do wish that Go and other languages had more bespoke functionality for dealing with required and optional parameters such as an automatic struct optional args, as well as multiple stacks for things like context.Context and error that might not be added initially but that could be discovered to be needed later. However, we do have to live in the world we've got and not in the one we only envision.

But we as both agreed on these topics, #fwiw. 🙂