开发者

in go, why []int instead of int[]? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, r开发者_高级运维eferences, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜