Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
cecd1636
Commit
cecd1636
authored
Feb 01, 2010
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
language FAQ entry on braces and semicolons
R=rsc, iant, gri CC=golang-dev
https://golang.org/cl/196075
parent
68796b02
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
go_lang_faq.html
doc/go_lang_faq.html
+30
-0
No files found.
doc/go_lang_faq.html
View file @
cecd1636
...
@@ -175,6 +175,36 @@ with the STL, a library for a language whose name contains, ironically, a
...
@@ -175,6 +175,36 @@ with the STL, a library for a language whose name contains, ironically, a
postfix increment.
postfix increment.
</p>
</p>
<h3
id=
"semicolons"
>
Why are there braces but no semicolons? And why can't I put the opening
brace on the next line?
</h3>
<p>
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.
</p>
<p>
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
<a
href=
"http://golang.org/cmd/gofmt/"
><code>
gofmt
</code></a>
,
<i>
some
</i>
style must be chosen. That style may differ from what
you've used in C or Java, but Go is a new language and
<code>
gofmt
</code>
'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.
</p>
<h3
id=
"garbage_collection"
>
<h3
id=
"garbage_collection"
>
Why do garbage collection? Won't it be too expensive?
</h3>
Why do garbage collection? Won't it be too expensive?
</h3>
<p>
<p>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment