One document about Go
Steven Schveighoffer
schveiguy at yahoo.com
Tue Jun 1 14:02:51 PDT 2010
On Wed, 02 Jun 2010 16:50:05 -0400, Alex Makhotin <alex at bitprox.com> wrote:
> Steven Schveighoffer wrote:
>> where we don't want to (I've done it many times). This is one of those
>> rare cases where people can easily type valid code that does not do
>> what they want.
>
> The reason I ask is because I sometimes do empty statements
> intentionally by placing a semicolon (surprised?). DMD doesn't allow me
> to do it, so I put {} as it asks.
No, not surprised. But compare the ratio of how many times someone wants
to have an empty loop/if statement to how many times someone accidentally
forms one. Empty loops are sometimes desired, and I think the pain of
requiring {} is worth the savings of not having accidents interpreted as
intentions.
> In contrast, Microsoft C/C++ does(with opt. /Wall):
>> warning C4390: ';' : empty controlled statement found; is this the
>> intent?
>
> I think it's correct way it should be done.
It is a judgement call, I think D made the right decision on disallowing
it, even without warnings turned on. In a couple weeks you will forget
about that one time you had to write an empty loop :)
> And about the question of omitting semicolon. I don't like the optional
> use of it. In this respect I don't like the GO's way it inserts
> semicolons automatically by the lexer(!).
>
> Just one excerpt from http://golang.org/doc/effective_go.html
>> One caveat. You should never put the opening brace of a control
>> structure (if, for, switch, or select) on the next line. If you do, a
>> semicolon will be inserted before the brace, which could cause unwanted
>> effects. Write them like this
>> if i < f() {
>> g()
>> }
>> not like this
>> if i < f() // wrong!
>> { // wrong!
>> g()
>> }
Oh, my, god. This is horrendous. Their *default* interpretation is "hey,
this guy obviously wants an if statement that does nothing"?
>
> I prefer ANSI(Allman) style(second example, wrong).
> They want to force Java-like style which I dislike much.
I do too. You will not find me using go until they change this.
-Steve
More information about the Digitalmars-d
mailing list