go - Most flexible function signature in golang -


I have an object anisor in my code, which clearly starts every field in my object. But in my case, most of the parameters have a lenient deficit and I want to use them.

In Python I usually use a combination of keyword logic or defaults and some validation logic in my __init __ method, so I use the zero configuration principle in the object initialization Can i For example:

  square fu: "" "This category is designed to show zero configuration principles in action" "def __init __ (self, mandatory, alternative = none, ** kwargs): self __field1 = mandatory self .__ field 2 = alternative or make_default2 () if quarards in 'bar': self .__ field 3 = quad ['bar'] and: self.__ field 3 = create_default 3 () f = Foo ('Entertainment', Bar = Bar)) Go to   

or go to the keyword parameter or function overload There is no parameter with the default value, due to that - it is difficult to write flexible initial code (I do not care much about performance in this type of code generally). I have got the most idiotic method to write such code in Go Maybe some combination of runtime type reflection and map will work, what do you think?

Memory allocation in the sphere Idyllic is always the idiotic way to use this fact:

  • To make your strings tiny zero values ​​
  • Using composite litterres < / li>

    Take a look at the following section of Go Go:

    For very complex cases, a configuration structure (on option 3) is sometimes used NewConfigrast () which is a configuration instance, Starts with T user generates a default Instalt that field sets like, then sends it to the New function of the actual code.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -