Skip to content

Commit

Permalink
content/static/doc/tutorial: don't "go run" individual files
Browse files Browse the repository at this point in the history
Go packages are implicitly made of all the files in a directory,
filtered by build tags. This is a core mechanic of using Go and of
contributing to Go projects. It's also different from many other
languages, including C and Rust, where code in different compilation
units can coexist in the same directory.

The only exception is when Go files are specified on the command line,
in which case a synthetic command-line-arguments package is composed
from them, ignoring build tags.

I don't think it helps beginners to expose them to this exception which
they would otherwise probably never make any use of.

This CL was motivated by hearing of a beginner being confused trying to
contribute to an existing project, because they were trying to "go run"
an individual file, which was failing with a wall of error because of
all the missing symbols from the other files in the package.

Change-Id: Iec0ef73df1c5ada2299d059dd468dc2095c367a8
Reviewed-on: https://go-review.googlesource.com/c/website/+/283635
Trust: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Steve Traut <straut@google.com>
  • Loading branch information
FiloSottile committed Jan 13, 2021
1 parent c818595 commit 713e774
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions content/static/doc/tutorial/getting-started.html
Expand Up @@ -114,7 +114,7 @@ <h2 id="code">Write some code</h2>
<ul>
<li>
Declare a <code>main</code> package (a package is a way to group
functions).
functions, and it's made up of all the files in the same directory).
</li>
<li>
Import the popular
Expand All @@ -127,7 +127,7 @@ <h2 id="code">Write some code</h2>
<li>
Implement a <code>main</code> function to print a message to the
console. A <code>main</code> function executes by default when you run
code in the file.
the <code>main</code> package.
</li>
</ul>
</li>
Expand All @@ -136,7 +136,7 @@ <h2 id="code">Write some code</h2>
Run your code to see the greeting.

<pre>
$ go run hello.go
$ go run .
Hello, World!
</pre
>
Expand Down Expand Up @@ -252,7 +252,7 @@ <h2 id="call">Call code in an external package</h2>
Run your code to see the message generated by the function you're calling.

<pre>
$ go run hello.go
$ go run .
go: finding module for package rsc.io/quote
go: found rsc.io/quote in rsc.io/quote v1.5.2
Don't communicate by sharing memory, share memory by communicating.
Expand Down

0 comments on commit 713e774

Please sign in to comment.