You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To compile this application, you need to switch to the application directory, which in this case is `$GOPATH/src/mathapp`, then execute the `go install` command. Now you should see an executable file called `mathapp` was generated in the directory `$GOPATH/bin/`. To run this program, use the `./mathapp` command. You should see the following content in your terminal.
90
93
91
94
Hello world. Sqrt(2) = 1.414213562373095
@@ -116,9 +119,9 @@ After executing the above commands, the directory structure should look like fol
116
119
Actually, `go get` clones source code to the $GOPATH/src of the local file system, then executes `go install`.
117
120
118
121
You can use remote packages in the same way that we use local packages.
119
-
122
+
```Go
120
123
import"github.com/astaxie/beedb"
121
-
124
+
```
122
125
## Directory complete structure
123
126
124
127
If you've followed all of the above steps, your directory structure should now look like the following.
Copy file name to clipboardExpand all lines: en/02.1.md
+6-3Lines changed: 6 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
## What makes Go different from other languages?
2
2
3
3
The Go programming language was created with one goal in mind, to be able to build scalable web-applications for large scale audiences in a large team. So that is the reason they made the language as standardized as possible, hence the `gofmt` tool and the strict usage guidelines to the language was for the sake of not having two factions in the developer base, in other languages there are religious wars on where to keep the opening brace?
4
+
```java
4
5
5
6
publicstaticvoid main() {
6
7
@@ -11,6 +12,7 @@ The Go programming language was created with one goal in mind, to be able to bui
11
12
{
12
13
13
14
}
15
+
```
14
16
or for python should we use 4 spaces or 6 spaces or a tab or two tabs and other user preferences.
15
17
16
18
While this might seem to be a shallow problem at the top, but when the codebase grows and more and more people are working on the same code base, then it is difficult to maintain the code's "beauty", if you know python then you might be aware of PEP8, which is a set of guidelines about how to write elegant code. We live in a world where robots can drive a car, so we shouldn't just write code, we should write elegant code.
@@ -40,15 +42,15 @@ Before we start building an application in Go, we need to learn how to write a s
40
42
According to international practice, before you learn how to program in some languages, you will want to know how to write a program to print "Hello world".
41
43
42
44
Are you ready? Let's Go!
43
-
45
+
```Go
44
46
package main
45
47
46
48
import"fmt"
47
49
48
50
funcmain() {
49
51
fmt.Printf("Hello, world or 你好,世界 or καλημ ́ρα κóσμ or こんにちは世界\n")
50
52
}
51
-
53
+
```
52
54
It prints following information.
53
55
54
56
Hello, world or 你好,世界 or καλημ ́ρα κóσμ or こんにちは世界
@@ -83,10 +85,11 @@ Each go file is in some package, and that package should be a distinct folder in
83
85
the thing here is that when your code is using some static files or something else, then you ought to run the binary from the root of the application as we see in the second line above, I am running the `main` binary *outside* the main package, sometimes you might wonder why your application isn't working then this might be one of the possible problems, please keep this in mind.
84
86
85
87
One thing you will notice here is that go doesn't see to use semi colons to end a statement, well, it does, just there is a minor catch, the programmer isn't expected to put semi colons, the compiler adds semi colons to the gocode when it compiles which is the reason that this (thankfully!) is a syntax error
86
-
88
+
```Go
87
89
funcmain ()
88
90
{
89
91
}
92
+
```
90
93
because the compiler adds a semi colon at the end of `main()` which is a syntax error and as stated above, it helps avoid religious wars, i wish they combine `vim` and `emacs` and create a universal editor which'll help save some more wars! But for now we'll learn Go.
0 commit comments