As a crazy random thought, wouldn't '@' work well as an alternative to the asterisk to dereference pointers? It's available, it's ASCII, it's pronounced "at" which seems to jive with pointer semantics, and it's not used in C-like languages.
Just a very quick thought after reading Mr Pike's closing words that the use of the asterisk for pointers makes the syntax a bit clumsier than they would have wished.
Anyone who has done a lot of bit twiddling in C has other uses for ^. (I find it ironic that 4^5 has an obvious meaning outside of programming that it doesn't have in a large variety of widely used programming languages.)
I suppose they should be allocated based on frequency of use within the intended domain of the language, with the most frequent getting first choice. I guess pointer dereferencing would be more important than xor for most domains. Not that I am particularly advocating ^ for pointers, * is just as good, but I do think using @ for the opposite of its meaning in Pascal would be confusing.
The more I use Go the more I realise how much thought has gone into every language decision and (just as importantly) how much restraint has gone into the design.
The declaration syntax contradicts the commentary.
Functions do not read from left to right. The example of
func main(argc int, argv *[]byte) int
is explained as "function main takes an int and a pointer to a slice of bytes and returns an int" but it should read "main is a function which takes an int and a pointer to a slice of bytes and returns an int" just like
x int
means "x is an integer". Reading left to right the variable name should come first for functions as for other variables so the function syntax should be
main func(argc int, argv *[]byte) int
But this can't be so because this appears to be the syntax that function variables use
f func(func(int,int) int, int) int
which is explained as "Here's a declaration of a function variable (analogous to a function pointer in C)".
Also the article says "Pointers are the exception that proves the rule" because "For familiarity, Go's pointers use the * notation from C, but we could not bring ourselves to make a similar reversal for pointer types.".
Putting these two observations together I would say that Go's declaration syntax fails in its stated mission of simplicity and regularity.
EDIT: can't seem to work out how to code markup on HN, anyway I hope I've made what I'm trying to say clear enough.
UPDATE: two spaces at the start of a line seems to work
Is an interesting idea... I don't think I've seen it in use anywhere (though I've mostly dealt with C-like). Add in the curly-braces for the definition, and you've just made functions into variables with blocks. And are they really any different anyway? The code-in-memory doesn't get duplicated when you make another instance, just the scope, so it's equivalent to a variable in a singleton.
I don't think I understand your first point.
The type for main would be
func(int, *[]byte) int
which reads left to right.
The function definition syntax isn't as left to right, but it's hardly complicated or confusing.
I think your points may be valid, but I don't think they lead to your conclusion that Go's syntax fails at its stated mission.
but the function _declaration_ should be (by the logic of the article and the stated intentions of their design decisions)
main func(argc int, argv *[]byte) int
and not
func main(argc int, argv *[]byte) int
because the variable name should come first as in
x int
and not
int x
In this way I fee that they have, if not failed, at least deviated from their stated or implied mission. But you're right, the type reads left to right.
I hope this is the last time I see "the exception that proves the rule" in the context of programming languages. It's a wart. You know what would better prove the rule? No exceptional cases at all.
Yes! Absolutely. The phrase "the exception proves the rule" is a tired, worn out, clichéd contradiction in terms that must have meant something at one time I'm sure but can only be superfluous in most cases now.
I think I've heard it used reasonably, but I can't really remember the specifics. Basically, it's when the cause for the exception follows naturally from the logic behind the rule. Contrived example: If something holds for most birds, an exception for penguins might qualify.
In any case, this is just an exception that breaks the rule.
Could use a better title... it's the golang.org's blog, and it's an explanation of the syntax, which is not really implied by "Go's declaration syntax". With just the domain and title, I'd assumed this was just documentation (as sometimes gets posted on hn), not discussion, and skipped over it several times.
All in all interesting, and I definitely agree with the improvement with their "function-returning function which accepts a function as an argument" example. An interesting departure from C & languages influenced by C (ie: most).
> "function-returning function which accepts a function as an argument"
I write almost exclusively Go day to day and I've noticed I no longer shy away from function pointers like in C. It's not that the C version can't be mastered, it's just that I'd rather not occupy a significant chunk of my brain with it.
Another interesting observation is that I can now pretty easily switch between C and Go if I need to, the declaration syntax seems different enough that my brain can do the leap. Sadly less true for semicolons (Go omits most, C doesn't)
Indeed. C-style declarations have always been intuitionally-opaque to me (I've always had to concentrate on them to get what they're saying), but the Go example:
f func(func(int,int) int, int) func(int, int) int
is a simple mechanical transformation away from being a Haskell declaration:
f :: ((Int, Int) -> Int, Int) -> (Int, Int) -> Int
great explanation and advocacy, and also good to see Pike's name as the author, gives the language a cred boost in my eyes. maybe i'll add it to the same bucket I consider D to be in as a possible successor to C for certain niches.
Just a very quick thought after reading Mr Pike's closing words that the use of the asterisk for pointers makes the syntax a bit clumsier than they would have wished.