Re: [go-nuts] Re: function's argument default value

2018-08-24 Thread Michael Jones
Reinforcing comments above: defaults are not *missing*, they have been *avoided*. One can argue default arguments are either a mistake in API design or neglect in code refactoring. On the mistake side, the argument is that making "cook(n)" mean "make pizza if n is missing or cook n if otherwise"

Re: [go-nuts] Re: function's argument default value

2018-08-24 Thread Louki Sumirniy
The distinction you are missing is that Go only considers the *name* of an interface method to be unique, meaning only one parameter definition is allowed per name. What this means is that in Go these have to be separate functions and by definition, differently named. This is why I am

Re: [go-nuts] Re: function's argument default value

2018-08-24 Thread Robert Johnstone
Hello, This is misleading. With default arguments, there remains only one function definition, which makes it quite different from function overloading where there would be multiple definitions. Default parameters provides syntax sugar at the call site, but does not create additional

Re: [go-nuts] Re: function's argument default value

2018-08-24 Thread Louki Sumirniy
I should just add one more thing, something I discovered when I saw the cete wrapper for the dgraph's badger KV store: https://github.com/1lann/cete If you design your interfaces carefully, and make it so that any function that does not by necessity return some other type, passes through the

Re: [go-nuts] Re: function's argument default value

2018-08-24 Thread Louki Sumirniy
This is in the next section but it's probably even more important: There is one more aspect of naming to be mentioned: method lookup is always by name only, not by signature (type) of the method. In other words, a single type can never have two methods with the same name. Given a method x.M,

Re: [go-nuts] Re: function's argument default value

2018-08-24 Thread Masoud Ghorbani
I found this talks which Rob Pike at syntax section explained why they omitted default function arguments. Thanks all about this discussion. On Friday, August 24, 2018 at 5:21:37 AM UTC+4:30,

Re: [go-nuts] Re: function's argument default value

2018-08-23 Thread Louki Sumirniy
I don't think the benefits are obvious and being able to leave out parameters by specifying one by name is of dubious benefit. Could you not simply write a short set of if statements that insert a default by using a nulled sentinel. Like this: func PrintMessage(s string) { if s == "" { s

Re: [go-nuts] Re: function's argument default value

2018-08-23 Thread Louki Sumirniy
I have to agree. The idiomatic solution would be defining multiple functions that wrap around another, and it is not onerously boilerplatey. As Ian says, default values do constitute effectively function overloads. There is reason why function overloading is not available in Go. Just go look

Re: [go-nuts] Re: function's argument default value

2018-08-23 Thread andrey mirtchovski
> You're right but I think developers of Go can think about that because its > benefits are obvious. can you please enumerate those benefits? many gophers are not convinced they are obvious. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

Re: [go-nuts] Re: function's argument default value

2018-08-23 Thread Masoud Ghorbani
You're right but I think developers of Go can think about that because its benefits are obvious. On Friday, August 24, 2018 at 1:23:32 AM UTC+4:30, Axel Wagner wrote: > > On Thu, Aug 23, 2018 at 9:44 AM Masoud Ghorbani > wrote: > >> Your opinion is like to say all of the python application

Re: [go-nuts] Re: function's argument default value

2018-08-23 Thread Ian Lance Taylor
On Thu, Aug 23, 2018 at 4:20 PM, Masoud Ghorbani wrote: > I didn't get the relation of function overloading with parameters default > value. actually, function overloading means define functions with similar > names. Right. After adding a default value for the parameter, you have two functions

Re: [go-nuts] Re: function's argument default value

2018-08-23 Thread Masoud Ghorbani
I didn't get the relation of function overloading with parameters default value. actually, *function overloading* means define functions with similar names. On Friday, August 24, 2018 at 1:11:12 AM UTC+4:30, Ian Lance

Re: [go-nuts] Re: function's argument default value

2018-08-23 Thread 'Axel Wagner' via golang-nuts
On Thu, Aug 23, 2018 at 9:44 AM 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. > One general thing to observe in all these discussions is, that Go is not Python (or Rust, Haskell,

Re: [go-nuts] Re: function's argument default value

2018-08-23 Thread Ian Lance Taylor
On Thu, Aug 23, 2018 at 12:44 AM, 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 >

[go-nuts] Re: function's argument default value

2018-08-23 Thread Louki Sumirniy
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

[go-nuts] Re: function's argument default value

2018-08-23 Thread Louki Sumirniy
Actually, my real opinion is that I like these default argument values, I also like concise asserts at the head of functions that automatically sanitise data. But they cost quite a lot which is likely why Go doesn't have them. Default arguments are the least useful of the two, asserts have a

[go-nuts] Re: function's argument default value

2018-08-23 Thread Masoud Ghorbani
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

[go-nuts] Re: function's argument default value

2018-08-22 Thread Louki Sumirniy
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