Re: [go-nuts] shadowing of types by variables
Yes, I understood the idea from Brian's explanation. Makes adding new predeclared names (types, literals...) a compatible change. Thanks. On Tue, Jan 17, 2023, 04:03 Ian Lance Taylor wrote: > On Mon, Jan 16, 2023 at 5:46 PM 'wagner riffel' via golang-nuts > wrote: > > > > On 1/13/23 07:20, Gorka Guardiola wrote: > > > According to the spec it seems like it is legal to shadow a type with a > > > variable, even a builtin type. > > > Is there any specific rationale for this? I guess that it makes scoping > > > checks easier and faster, but still. > > > > > > > I don't think there is any special rationale behind it, in Go builtin > > types are predefined identifiers, not keywords as usual in other > > languages, thus those follow rules of identifiers, not keywords. > > Although it feels astonishing that you can shadow even predefined > > constants like "true := false", in my experience this haven't shown to > > be an issue. > > There is a rationale: we can add new predeclared identifiers without > breaking existing working code. > > For example, the Go 1.18 release added two new predeclared > identifiers: `any` and `comparable`. Because they were predeclared > identifiers, not keywords, existing code that used them as variable > names continued to work. > > 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/CACm3i_hbKDGq_WObfN1RHp2nC81%2B6QbsudASP7txpnsMT_UEEw%40mail.gmail.com.
Re: [go-nuts] shadowing of types by variables
On Mon, Jan 16, 2023 at 5:46 PM 'wagner riffel' via golang-nuts wrote: > > On 1/13/23 07:20, Gorka Guardiola wrote: > > According to the spec it seems like it is legal to shadow a type with a > > variable, even a builtin type. > > Is there any specific rationale for this? I guess that it makes scoping > > checks easier and faster, but still. > > > > I don't think there is any special rationale behind it, in Go builtin > types are predefined identifiers, not keywords as usual in other > languages, thus those follow rules of identifiers, not keywords. > Although it feels astonishing that you can shadow even predefined > constants like "true := false", in my experience this haven't shown to > be an issue. There is a rationale: we can add new predeclared identifiers without breaking existing working code. For example, the Go 1.18 release added two new predeclared identifiers: `any` and `comparable`. Because they were predeclared identifiers, not keywords, existing code that used them as variable names continued to work. 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/CAOyqgcXt%2BJ6_S_ndgGuxL3zqG1sZjnQ5ahvLd0hfPpWjAS_NLg%40mail.gmail.com.
Re: [go-nuts] shadowing of types by variables
On 1/13/23 07:20, Gorka Guardiola wrote: According to the spec it seems like it is legal to shadow a type with a variable, even a builtin type. Is there any specific rationale for this? I guess that it makes scoping checks easier and faster, but still. I don't think there is any special rationale behind it, in Go builtin types are predefined identifiers, not keywords as usual in other languages, thus those follow rules of identifiers, not keywords. Although it feels astonishing that you can shadow even predefined constants like "true := false", in my experience this haven't shown to be an issue. -w -- 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/ff5efae5-937e-32dd-608a-8d8ac8d0417b%40104d.net.
[go-nuts] shadowing of types by variables
These programs compile and work according to my reading of the spec, but I found them surprising. https://go.dev/play/p/EUZ_28jge1N https://go.dev/play/p/NMhR1Nq1COw According to the spec it seems like it is legal to shadow a type with a variable, even a builtin type. Is there any specific rationale for this? I guess that it makes scoping checks easier and faster, but still. More "interesting" programs in the same vein: https://go.dev/play/p/_KburW2YuCG https://go.dev/play/p/JTkvW7jsvyX https://go.dev/play/p/tDji-HNo1_W -- - curiosity sKilled the cat -- 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/CACm3i_gG9yA3timw8PF4FZ%2B5%3DtXYich4fLBT%3DXHU5-y%3DRxC0%2BQ%40mail.gmail.com.