Skip to content

New semicolon rule breaks 'if then{} newline else{}' #416

@gopherbot

Description

@gopherbot

by ray@hollett.demon.co.uk:

I really like the new semicolon rules, but a standard layout pattern for
many people is to have 'else' on a new line.
As in:

if 1 == 2 { fmt.Println("line 1") }
else { fmt.Println("line 2") }

or:

if 1 == 2 {
    fmt.Println("line 1")
}
else {
    fmt.Println("line 2")
}

However both these cause a "syntax error near else". What now is required
is that the newline before the else is removed to give: } else {
This is what gofmt does, but I do not understand the reasons for it based
on the proposal given a few days ago for the new semicolon rules.
I notice that the Channels example in "Go For C++ Programers" is in the now
broken format:
if c.get { c.val = val; ch <- c }
else { val = c.val }

Personally I prefer a newline before else rather than "} else {", but I
prefer the new semicolon rules more.

What is your $GOOS?  $GOARCH?
linux (Ubuntu 9.10) 386 (8g)

Which revision are you using?  (hg identify)
e7f3b2a4d933 tip (I updated today)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions