On Tue, 18 Sep 2018 11:10:00 -0500
robert engels <reng...@ix.netcom.com> wrote:

> I’ve said many time, the CGG example you cite here is not generic code.

I do not want neither write nor **READ** Go++ code.

CGG is called Craftsman's for a reason.

Its for writing and **reading** real production code. It disallows, by the
very construction, fancy recurrent types and other metaprogramming that
allows "clever guys" to encipher unreadable math with yet less readable
syntax.


> I want to pass a different user type and use that method I can’t, I need to
> change the source of Sum(). That is not generic programming...

Wrong! CGG allows operations in terms of base type (thats the num case) And
in terms what a type have or can. It's just a matter of contract.

Any person who actually got to **read** and understand CGG proposal would
spot the possibility of more generic contract by oneself:

func (x type []K) Sum() (r type K) {
 for type switch {
 case K range int64(), uint64(), float64(), complex128():
      for _, v := range x {
         r += v
      }

 // case K big.Int: was a simple example for Alan's stated problem

 // lets make it more general for Robert:
 // allow for any type that has a Sum (to itself) method:

 case K (*K) Add(K, K): 
      for _, v := range x {
         r.Add(r,v)
      }

 // Or, that has a value method that returns sum with self
 case K (K) Add(K) K:
      for _, v := range x {
         r = r.Add(v)
      }
  break  // or return in every case instead
 }
 return
}

> I need to change the source of Sum().
It is **me** as a generic implementer to change the source of Sum, or to
write it for some special cases as the value method case above.
If its in a lib, raise issue. I'll answer why I have omitted your outstanding
type. Or I'll implement it.

In either case, you can see the source and infer whether your type will pass
just by reading straight Go code slightly guarded by the constraints on
**types**.


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

Reply via email to