in go, why []int instead of int[]? [closed]
this syntax was started quite some time ago, and I do not understand its appeal
to me, even with initialization,
var arr int[2]{ 1, 2 } // wrong!
is more readable than
var arr [2]int{ 1, 2 } // to me this seems klutzy
before more people get on my case, please see notes, and link in answer was exactly the info I was seeking.
The second way is more readable to me. It's an opinion thing. Since you didn't create the language, your opinion wasn't the one adopted.
There may have also been other factors, such as the second way being easier to parse.
Here's a blog post on the Go syntax choices. It sounds like it was mostly about readability.
Also, this difference from C might play a part (found here):
The size of an array is part of its type. The types [10]int and [20]int are distinct.
精彩评论