TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Go's Declaration Syntax

68 pointsby pufuwozualmost 15 years ago

8 comments

igraviousalmost 15 years ago
The declaration syntax contradicts the commentary.<p>Functions do not read from left to right. The example of<p><pre><code> func main(argc int, argv *[]byte) int </code></pre> 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<p><pre><code> x int </code></pre> 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<p><pre><code> main func(argc int, argv *[]byte) int </code></pre> But this can't be so because this appears to be the syntax that function variables use<p><pre><code> f func(func(int,int) int, int) int </code></pre> which is explained as "Here's a declaration of a function variable (analogous to a function pointer in C)".<p>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.".<p>Putting these two observations together I would say that Go's declaration syntax fails in its stated mission of simplicity and regularity.<p>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.<p>UPDATE: two spaces at the start of a line seems to work
评论 #1499070 未加载
评论 #1498030 未加载
评论 #1497719 未加载
评论 #1497529 未加载
unwindalmost 15 years ago
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.<p>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.
评论 #1496775 未加载
评论 #1526799 未加载
enneffalmost 15 years ago
Includes a discussion of C's declaration syntax. Some stuff in there I didn't know.
sambeaualmost 15 years ago
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.<p>It's my first tool of choice for everything now.
mkramlichalmost 15 years ago
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.
Groxxalmost 15 years ago
Could use a better title... it's the golang.org's <i>blog</i>, and it's an explanation <i>of</i> 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.<p>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 &#38; languages influenced by C (ie: most).
评论 #1496680 未加载
评论 #1496549 未加载
评论 #1497408 未加载
jeberlealmost 15 years ago
You might compare the results with SPECS: <a href="http://en.wikipedia.org/wiki/Significantly_Prettier_and_Easier_C%2B%2B_Syntax" rel="nofollow">http://en.wikipedia.org/wiki/Significantly_Prettier_and_Easi...</a> -- an alternate syntax for C++. I find its productions clearer than those of Go's.
heatdeathalmost 15 years ago
We took what you're used to... and flipped it around! Did I just blow your mind??