Answer the question
In order to leave comments, you need to log in
How to avoid a large number of arguments in functions?
In general, I wrote a program, and then it was necessary to introduce several additional features, due to which instead of 2-3 arguments there are now 5 arguments in functions. in so many arguments?
Answer the question
In order to leave comments, you need to log in
Ideally, redo.
If it is not possible to remake, the structures will definitely be better.
There is also a "functional options" option https://golang-blog.blogspot.com/2019/10/functiona...
Use functional options with prescribed default values
https://m.habr.com/ru/post/489296/
Or wrap optional fields in a structure and pass the structure as a function parameter.
If it is possible to remake a function so that it requires fewer arguments, then it is better to do so, for example, split it into 2 functions, if one depends on the other and because of this you have to pass more parameters than necessary.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question