If you have type checking / casting / type select, whatever you want to call it 
in the “generic code”, it is not generic, and not re-usable.

You can’t possibly know all the possible types, there may even be more 
additional primitive types, so the code is not resilient - Go 2.1 and all of 
your library code breaks?

The caller will not have access to the source code (and certainly not want to 
read it to call a function). Nothing will be obvious as to what Sum can work on 
or what it does - in fact you can have very subtle errors because the code is 
duplicated across types.

Besides those problems, even if it was somehow workable, the syntax reuses 
keywords in non-standard ways (for example even if this was adopted, why 
wouldn’t the syntax be:

switch K {
    case (int64,unint64,…):
        blah blah blah
    case big.Int
        blah blah blah
    default:
        panic // implied
}

The compiler already knows K is a type…

And yet more problems, because you probably need every combination of types if 
it has more than one, (depending on what the method does) — you need an n*n 
number' of case statements to implement it….

I am just being realistic, and I don’t mean to be harsh, but I don’t think your 
proposal is going to be accepted, and I think it might be better if you spent 
more time listening to the criticism, and maybe reworking, than trying to 
defend it. I guess there is always the chance I don’t get it, but I think I do…

Not sure how else to explain it. 


> On Sep 18, 2018, at 3:53 PM, Wojciech S. Czarnecki <o...@fairbe.org> wrote:
> 
> On Tue, 18 Sep 2018 10:11:52 -0700 (PDT)
> mhhc...@gmail.com wrote:
> 
>> I agree with Robert, this is not re usable.
> 
> What is not reusable? A generic Sum function allowed by
> the CGG that can sum any type of any base that accidentally
> has anything countable in it?
> 
>> I much prefer this 
>> 
>> func Sum(some []K, add func(l,r K) K) (ret K) {
>>  for _, v := range some {
>>    ret = add(ret, v)
>>  }
>>  return ret 
>> }
>> 
>> func main(){
> 
> 
>>  total := Sum([]int{1,2,3,4}, func(l,r int) int {return l+r})
>> }
> 
> How clever and generic it looks. Generic, javish and cpluplusish.
> And how readable call site it gave.
> 
> In CGG Go user code call is exactly the same for ANY type.
> 
> total := Sum(x) // For var x []AnyType. ANY. 
> 
> var x []string
> total := Sum(x)
> 
> may return sum of all runes in all strings and sprintf-ed to
> the resulting string.
> 
>> this is not re usable.
> 
> How can I call your example to get string result of sum of all
> runes? CGG's is as with any other type: `total := Sum(x)`
> 
> -- 
> Wojciech S. Czarnecki
> << ^oo^ >> OHIR-RIPE
> 
> -- 
> 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.

-- 
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