Allow name : type declarations?

134 views
Skip to first unread message

Hugh Fisher

unread,
Apr 22, 2018, 12:39:47 AM4/22/18
to golang-nuts
I'm a new Go programmer (learning in my spare time) and decided to share my
initial fumbles and what? why? moments while they're still fresh.

First suggestion: allow a colon to be inserted between the name(s) and type
in declarations. For example
x : int
func random(): real 
        
Back in the previous century I wrote a lot of Pascal code and a little Ada, so
I'm fine with the idea of Go reversing the declaration syntax away from C. But
because of that experience I keep typing a colon between the names.

For those without Pascal experience, I still think it would be worthwhile for
consistency and readability.

Consistency: we already have name = value and name := value and type.
The : becomes the 'type declaration' operator.

For readability, while I appreciate the intent to shorten the code, I find it takes
longer for me to parse

x, y, z int

because the absence of the comma is what matters. It's significant white space,
(which again I'm generally OK with) but very short. I find it harder to look for
something that isn't there, rather than a divider or delimiter. Already I seem to
be inserting extra spaces before the type name just to make it stand out.

cheers,
Hugh Fisher

Ian Lance Taylor

unread,
Apr 24, 2018, 12:52:36 AM4/24/18
to Hugh Fisher, golang-nuts
Thanks for the note. The truth is, regardless of the merits of this
suggestion, it's too late to make this kind of change to the language.

Ian

Hugh Fisher

unread,
Apr 24, 2018, 7:37:29 AM4/24/18
to golang-nuts


On Tuesday, April 24, 2018 at 2:52:36 PM UTC+10, Ian Lance Taylor wrote:

Thanks for the note.  The truth is, regardless of the merits of this
suggestion, it's too late to make this kind of change to the language.

Ian

 Yeah I know, but there's talk of a Go 2 at some stage...

Ian Lance Taylor

unread,
Apr 24, 2018, 8:50:36 AM4/24/18
to Hugh Fisher, golang-nuts
There will definitely be a Go 2, but Go 2 will be almost entirely and
perhaps completely backward compatible with Go 1. The experiences of
other languages makes it clear that we break backward compatibility at
our peril. This extends to things like adding new declaration syntax.
We can make such changes in Go 2, but we will only make them for the
most compelling of reasons. Reasons like "this is more like Pascal"
or "this makes the declaration syntax more consistent and readable"
aren't compelling enough. Sorry.

If you really want to push this, you'll need to open a proposal, as
described at https://github.com/golang/proposal/blob/master/README.md.
But I very much doubt that such a proposal would be accepted.

Thanks again.

Ian
Reply all
Reply to author
Forward
0 new messages