From: Rob Pike Date: Mon, 1 Feb 2010 09:45:29 +0000 (+1100) Subject: language FAQ entry on braces and semicolons X-Git-Tag: weekly.2010-02-04~47 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cecd16362580c8b7efc3db111f5bc4045641024d;p=gostls13.git language FAQ entry on braces and semicolons R=rsc, iant, gri CC=golang-dev https://golang.org/cl/196075 --- diff --git a/doc/go_lang_faq.html b/doc/go_lang_faq.html index 23d634b853..1a8ffcf030 100644 --- a/doc/go_lang_faq.html +++ b/doc/go_lang_faq.html @@ -175,6 +175,36 @@ with the STL, a library for a language whose name contains, ironically, a postfix increment.

+

+Why are there braces but no semicolons? And why can't I put the opening +brace on the next line?

+

+Go uses brace brackets for statement grouping, a syntax familiar to +programmers who have worked with any language in the C family. +Semicolons, however, are for parsers, not for people, and we wanted to +eliminate them as much as possible. To achieve this goal, Go borrows +a trick from BCPL: the semicolons that separate statements are in the +formal grammar but are injected automatically, without lookahead, by +the lexer at the end of any line that could be the end of a statement. +This works very well in practice but has the effect that it forces a +brace style. For instance, the opening brace of a function cannot +appear on a line by itself. +

+

+Some have argued that the lexer should do lookahead to permit the +brace to live on the next line. We disagree. Since Go code is meant +to be formatted automatically by +gofmt, +some style must be chosen. That style may differ from what +you've used in C or Java, but Go is a new language and +gofmt's style is as good as any other. More +important—much more important—the advantages of a single, +programmatically mandated format for all Go programs greatly outweigh +any perceived disadvantages of the particular style. +Note too that Go's style means that an interactive implementation of +Go can use the standard syntax one line at a time without special rules. +

+

Why do garbage collection? Won't it be too expensive?