2017-10-17 12:10
浏览 168


why is there a comma in this variable declaration:

// RinkebyBootnodes are the enode URLs of the P2P bootstrap nodes running on the
// Rinkeby test network.
var RinkebyBootnodes = []string{
    "enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@", // IE
    "enode://343149e4feefa15d882d9fe4ac7d88f885bd05ebb735e547f12e12080a9fa07c8014ca6fd7f373123488102fe5e34111f8509cf0b7de3f5b44339c9f25e87cb8@",  // INFURA

I am talking about comma that goes here:

30303",  // INFURA

it is the last character of the string array, and it has to go there, otherwise I get a compile error.

In C language you can't have commas at the end of curly braces {} , but in go you have to. Why ? And what does this comma mean?

图片转代码服务由CSDN问答提供 功能建议


   // RinkebyBootnodes是P2P引导节点上成
 // Rinkeby测试网络\ NVAR RinkebyBootnodes = []串{
运行该e节点的URL。 “e节点://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@”,// IE  
“ enode:// 343149e4feefa15d882d9fe4ac7d88f885bd05ebb735e547f12e12080a9fa07c8014ca6fd7f373123488102fe5e34111f8509cf0b7de3f5b44339c9f25e87cb8 @ n   p> 
  30303“,// INFURA 


在C语言中,花括号{}的末尾不能有逗号,但是在旅途中,必须这样做。为什么? 这个逗号是什么意思?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanpingzu7194 2017-10-17 18:15

    Comma is an element splitter. Elements could be.written as in a row so in a column:

    {1, 2, 3}

    It’s evident comma is unnecessary after the last element. Some languages require their absense like C, some - presence like Go, some allow both variants like Python. Sometimes it causes bugs like with JavaScript in old Internet Explorer.

    Why do gophers decide to keep this comma? One of key principles of Go is visual simplicity and readability. This way all the strings look the same way. It’s easier to read them by eyes. Also suppose you add one more line - you have to edit previous one. And this creates visual noise in diff.

    Thinking the same you get to the idea comma should not be in one liners. Because spoils readability as extra symbol.

    打赏 评论

相关推荐 更多相似问题