On Thu, Aug 20, 2020 at 10:54 PM Ian Lance Taylor <i...@golang.org> wrote:
>
> On Thu, Aug 20, 2020 at 8:52 PM burak serdar <bser...@computer.org> wrote:
> >
> > On Thu, Aug 20, 2020 at 8:22 PM Jan Mercl <0xj...@gmail.com> wrote:
> > >
> > > On Fri, Aug 21, 2020 at 2:28 AM Ian Lance Taylor <i...@golang.org> wrote:
> > >
> > > > To simplify the common case of a type parameter that has
> > > > no constraints, we will introduce a new predeclared identifier “any”
> > > > as an alias for “interface{}”.
> > >
> > > Anyone can write the declaration
> > >
> > >         type any = interface{}
> > >
> > > today and possibly some people already do that. But in my opinion that
> > > would, so far, not pass a code review within the Go project per se.
> > > (It would definitely not pass my code review.)
> > >
> > > I don't like it and It makes me sad it is being proposed to become
> > > officially blessed.
> >
> > Is "any" truly an alias for interface{}, or is it only a constraint? I
> > agree with Jan's point that replacing interface{} with "any" might
> > unintentionally encourage its use.
>
> Our intent here is that "any" will be available for all code.  Yes, we
> wouldn't do it if it weren't for its use as a type constraint.  But if
> we are going to do it for type constraints, there seems to be little
> benefit to restricting it to only work as a type constraint.

What worries me is code like this:

func f() any {
   int *i
  return i
}

func main() {
   if f()==nil {
    ...
   }
}

Use of "any" makes it look like f returns an *int and f() is nil, but
it is not, because "any" is interface{}.

I think "any" as a constraint is useful, like "comparable", but "any"
as a type is misleading.




>
> This is not, of course, a new idea, even in the absence of generics.
> For example, https://golang.org/issue/33232.  (My comment there was
> that we would use interface{} less if we had generics, but of course
> when we require type constraints then we actually wind up using it
> somewhat more.)
>
> Ian

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMV2Rqqr0AGtcJEJhv0UPtO8vgPShfs%3DxdBj5U7Wgjtyb%2BMoZg%40mail.gmail.com.

Reply via email to