Remix.run Logo
hackerbrother 4 days ago

Along these lines, Go eliminates many formatting decisions at the syntax level. E.g.,

  func main()
  {
          fmt.Println("HELLOWORLD")
  }
is not just non-standard formatting, but illegal Go syntax. Similarly, extra parentheses around if clauses are not allowed.
TheDong 4 days ago | parent [-]

> Similarly, extra parentheses around if clauses are not allowed.

However 'if (x) == (1) {}' is totally fine with the formatter. As is an assignment of '(x) = (y)'.

It's actively annoying too because like, extra parenthesis often have important meaning.

For example, consider the following code:

    if (x.isFoo() || x.isBar()) /* && x.isBaz() */ { /* code */ }
In that case, the code is obviously temporarily commented out, but go's formatting will make it so that if you comment it out like that, fmt, and then uncomment it and forget to re-add the parens, you get shot in the foot.

I've hit that far more times than it's uhh... I dunno, I guess removed parenthesis I didn't want? I don't write them if I don't want them.

lsaferite 3 days ago | parent | next [-]

FWIW, in that scenario, for the reasons you've called out, I would normally dupe the if line and comment the original one for reference. Mind you, none of that would ever get committed, but for a temp local change it's fair game.

lsaferite 3 days ago | parent | prev [-]

go is generally hostile to temporarily commenting out code. The if syntax issue you call out is just one aspect. Another is the inability to have unused variables.