Actually, going a little further, I would like to see a change in Golang 
where parameter and return tuples can be set the same way as structs - so 
if you use named labels ( label="value ) it assumes null for any others 
specified. Then you can add one more feature, which is also related and 
gives you what you want - that you can specify defaults inside the 
parameter block in a function header for values when you want something 
other than null values when unspecified using labels.

On Thursday, 23 August 2018 09:44:17 UTC+2, Masoud Ghorbani wrote:
>
> Your opinion is like to say all of the python application should rethink 
> and re-write their structure because they used default values. I think 
> having default values for parameters is just a feature which will make 
> codebase readable and smaller than before.
>
> On Thursday, August 23, 2018 at 4:38:23 AM UTC+4:30, Louki Sumirniy wrote:
>>
>> There is a default value for everything in Go. Null. 0, "" and nil. As 
>> someone else said, if you want a parameter to be optional you probably need 
>> ...interface{} and then infer no parameter as 'use the default'. Going a 
>> little further, you can build default values into a constructor function 
>> for an interfaced type. 
>>
>> Oh, probably the neatest solution is to make a struct that lets you input 
>> the parameters either in-order or with labels instead. Then you can use 
>> &TypeName{} to mean 'use defaults' or whichever parameters are not 
>> specified get automatically set to default, either unlabeled and ordered 
>> such that the values that will be asserted to defaults are not the first 
>> ones in a struct literal used to feed parameters in. Or make the names nice 
>> and concise so they aren't troublesome to add (and if your code is going to 
>> often use defaults, probably you won't even have to specify many values 
>> very often anyway).
>>
>> Assertions and labeled parameters are nice features but they don't really 
>> save you that much time. I would suggest that it's more likely you need to 
>> rethink the structure of your application and make slightly different named 
>> parameters for those calls that will use defaults for specific parameters.
>>
>> Another thing is that you can make null variables imply the use of 
>> defaults, then you only need to put 'nil' '""' or '0' into these parameters 
>> and the code will test and fill them automatically. Or if null isn't handy, 
>> you can define sentinel values for a type that indicate 'use defaults'.
>>
>> On Wednesday, 22 August 2018 14:39:37 UTC+2, Masoud Ghorbani wrote:
>>>
>>> Why there isn't function argument default value in Golang explicitly 
>>> like Typescript and Python?
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to