Re: [go-nuts] formatting question/issue

2018-04-10 Thread Jan Mercl
On Tue, Apr 10, 2018 at 1:32 AM Alex Dvoretskiy 
wrote:

> Why there is no difference if the last comma exists?

Because the language specification allows to omit the last comma before the
closing '}':

LiteralValue = "{" [ ElementList [ "," ] ] "}" .

See: https://golang.org/ref/spec#LiteralValue

-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] formatting question/issue

2018-04-09 Thread Tyler Compton
My understanding is that this is a consequence of the semicolon insertion
rules Go uses. The Go parser actually uses semicolons internally, but they
are inserted before parsing so that the programmer doesn't have to.

Semicolons are added to the end of a line if the line ends with:
 - an identifier
 - an integer, floating-point, imaginary, rune, or string literal
 - one of the keywords break, continue, fallthrough, or return
 - one of the operators and delimiters ++, --, ), ], or }
(Taken from this article:
https://medium.com/golangspec/automatic-semicolon-insertion-in-go-1990338f2649
)

In your second example on line 18, "true" is an identifier so a semicolon
would be inserted there. Obviously this would make for invalid code,
because that place is not the end of an expression. Adding a comma lets the
semicolon inserter know that there is more to this expression so it doesn't
add a semicolon.

It's an interesting suggestion to make the comma obligatory. My first
impression is that it would lead to even more surprises to programmers from
other languages.

On Mon, Apr 9, 2018 at 4:32 PM Alex Dvoretskiy 
wrote:

> Hello Golangnuts,
>
> Why there is no difference if the last comma exists?
>
> {'A', 'B', 'C', 'E'}
> or
> {'A', 'B', 'C', 'E',}
>
> both are valid.
>
>
> Sometimes it causes little troubles. For example, the second snippet
> wouldn't compile, because of different formatting. But these two snippets
> are identical technically. So, you have to add this last comma to keep the
> formatting you want. Which can be annoying.
>
> https://play.golang.org/p/4Vav9n2_NIc
>
> https://play.golang.org/p/pr2h6_FBxFn
>
>
> I think it's very good idea to make the last comma obligatory.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] formatting question/issue

2018-04-09 Thread Alex Dvoretskiy
Hello Golangnuts,

Why there is no difference if the last comma exists?

{'A', 'B', 'C', 'E'}  
or
{'A', 'B', 'C', 'E',}

both are valid.


Sometimes it causes little troubles. For example, the second snippet 
wouldn't compile, because of different formatting. But these two snippets 
are identical technically. So, you have to add this last comma to keep the 
formatting you want. Which can be annoying.

https://play.golang.org/p/4Vav9n2_NIc

https://play.golang.org/p/pr2h6_FBxFn


I think it's very good idea to make the last comma obligatory.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.