3 ms·
> Go is also the only place I've ever seen this syntax: Do you mean if blah { code } else { code } as in parens-less if statement
by masklinn 14y ago
> Go is also the only place I've ever seen this syntax:
Do you mean
if blah {
code
} else {
code
}
as in parens-less if statement? Because I don't see anything odd in what you wrote, it's valid C or Java.
And if it's putting else, } and { on the same line, it's "standard" K&R, 1TBS, BSD KNF and java indent style/coding conventions.
- jmduke 14y agoI believe he's referring to the latter -- as opposed to: if blah { code } else { code } Personally, I don't prefer the K&R way but I don't think it's either strange nor troublesome enough to worry about for more than a few seconds.
- samatman 14y agoThe argument is that putting anything between } and else breaks the else statement, so using } else { stresses that you cannot add statements either before or after the else.
- shadowmint 14y agoit is weird they made that the only valid syntax
- masklinn 14y agoWhat you stated is not just that (which is not actually weird), but — quoting you > Go is also the only place I've ever seen this syntax compounded by > Maybe that's popular in some obscure places (thus calling Java's coding conventions or the K&R "obscure places")
- doktrin 14y agoI don't understand why this comment is being downvoted. I just learned something. If Go enforces a specific coding convention at the compiler level, then that could legitimately be considered at least slightly unusual. While it's true that this style is far from esoteric, it's also typically just that ( a coding style ). This strikes me as at least somewhat analogous to Python's whitespace indentation rules or Java's checked exceptions, in that what is typically a design choice is enforced by the compiler / interpreter.
- CatMtKing 14y agoIt's a great choice for readability; cuts down on inconsistency.
- wonderzombie 14y agoIt's because of arguments like this, that's why. They render a huge swath of subjective, unproductive discussions about style completely moot.
- jlgreco 14y agoWell, that is the idea at least. Unfortunately it almost seems as though the style arguments will be replaced with the "pro/against enforced style" arguments. Hopefully this new topic has less staying power.
- coldtea 14y agoNot, it's very pragmatic, based on a parser need (to make it simpler), and it's well explained in their docs. Not to mention that's a well known style, has a lot of benefits (less wasted lines compared to the style that puts both brackets on empty lines, less potential for errors in than when you omit the brackets for a single statement), and, most importantly, puts and end to all bikeshedding. Especially along with gofmt, go is a bikeshedding free language in regards to syntax.