English English English

So many run ons, personal thoughts, unclear references.
This commit is contained in:
Spellchaser
2017-10-10 11:53:16 -04:00
committed by GitHub
parent 52dc19c20c
commit 8b9d089137

View File

@@ -13,25 +13,27 @@ The Go programming language was created with one goal in mind, to be able to bui
}
```
or for python should we use 4 spaces or 6 spaces or a tab or two tabs and other user preferences.
or for python should we use 4 spaces or 6 spaces or a tab or two tabs and other user preferences. If you know python then you might be aware of PEP8, which is a set of guidelines about how to write elegant code.
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.
While this might seem to be a shallow problem, when the codebase grows and more and more people work on the same code base it is becomes increasingly difficult to maintain the code's "beauty." We live in a world where robots can drive a car, so we shouldn't just write code, we should write elegant code.
For other languages there are many variables when it comes to writing code, every language is good for its use case, but Go is a little special in that turf because it was designed at a company which is the very synonym of the Internet (and distributed computing), typically the flow of writing code goes from Python to Java to C++ for optimization purposes, but the problem is that almost all languages which are widely in use right now were written decades ago when 1GB storage came at a much higher price compared to now, where storage and computing has gotten cheap. Computers are getting multiples cores these days and the "old languages" don't harness concurrency in a way that go does, not because those languages are bad, but simply because that usecase wasn't relevant when the languages evolved.
For other languages there are many variables when it comes to writing code. Every language is good for its use case, but Go is a little special because it was designed at a company which is the very synonym of the Internet (and distributed computing). Typically in order to optimize programs, developers choose to write Java over Python and C++ over Java, but almost all available languages widely in use were written decades ago when 1GB storage was much pricier. Now storage and computing is relatively cheap and computers are getting multiples cores, but the "old languages" are not harnessing concurrency in a way that go does. It's not because those languages are bad; utilizing concurrency wasn't a relevant usecase while the older languages evolved.
So to mitigate all the problems that Google faced with the current tools, they wrote a systems language called Go, which you are about to learn! There are many advantages to using golang, and there might be disadvantages too for every coin has both sides. But significant improvements in places like code formatting, since they designed the language in such a way that there won't be wars on how to format code, the gocode written by anyone in the world (assuming they know and use `gofmt`) will look exactly the same, this won't seem to matter until you work in a team! also when the company uses automated code review or some other fancy technique then in other languages which don't have strict and standard formatting rules then the code might get screwed up, but not in go!
To mitigate all the problems that Google faced with current tools, they wrote a systems language called Go which you are about to learn! There are many advantages to using golang and there are disadvantages too, for every coin has both sides. One of the significant improvements in in code formatting. Google has designed thte language to avoid debates on code formatting. Go code written by anyone in the world (assuming they know and use `gofmt`) will look exactly the same. This won't seem to matter until you work in a team! Also when the company uses automated code review or some other fancy technique, the formatted code may break in other languages which don't have strict and standard formatting rules, but not in go!
Go was designed with concurrency in mind, please note that parallelism != concurrency, there is an [amazing post](https://blog.golang.org/concurrency-is-not-parallelism) by Rob Pike on the [golang blog](https://blog.golang.org/), you will find it there, it is worth a read.
Another very important change that go has brought in programming that I personally love is the concept of `GOPATH`, gone are the days when you had to create a folder called `code` and then create workspaces for eclipse and what not, now you have to keep one folder tree for go code and it'll be updated by the package manager automatically. Also under the code we are recommended to create folders with either a custom domain or the github domain, for example I created a task manager using golang so I created a set of folders
`~/go/src/github.com/thewhitetulip/Tasks` note: In *nix systems `~` stands for home directory, which is the windows equivalent of `C:\\Users\\username`
now the `~/go/` is the universe for the gocode in your machine, it is just a significant improvement over other languages so we can store the code efficiently without hassles, it might seem strange at first, but it does make a lot of sense over the ridiculous package names some other languages use like reverse domains.
Another very important change that is the concept of `GOPATH`. Gone are the days when you had to create a folder called `code` and then create workspaces for eclipse and what not. Now you have to keep one folder tree for go code which will be updated by the package manager automatically. It is also recommended to create folders with either a custom domain or the github domain, for example I created a task manager using golang so I created a set of folders
`~/go/src/github.com/thewhitetulip/Tasks`
**Note:** In *nix systems `~` stands for home directory, which is the windows equivalent of `C:\\Users\\username`.
Now the `~/go/` is the universe for the gocode in your machine. This is a significant improvement over other languages; we can store the code efficiently without hassles. While it might seem strange at first, this approach make a lot of sense than the ridiculous package names, i.e. package names generated for other languages using reverse domains.
**Note:** Along with `src` there are two folders `pkg` which is for packages and `bin` which is for binary.
This `GOPATH` advantage isn't just restricted to storing code in particular folder, but when you have created five packages for your project then you don't have to import them like `"import ./db"`, you can give it `import "github.com/thewhitetulip/Tasks/db"`, so while doing a `go get` on my repo, the `go` tool will find the package from `github.com/...` path if it wasn't downloaded initially, it just standardizes a lot of screwed up things in the programming discipline.
This `GOPATH` advantage isn't just restricted to storing code in particular folder. When you have created five packages for your project, you don't have to import them like `"import ./db"`. Instead you can use `import "github.com/thewhitetulip/Tasks/db"` so that when executing `go get` on my repo, the `go` tool will find the package from `github.com/...` path if it wasn't downloaded initially. This standardizes a lot of screwed up things in the programming discipline. (<-- To remove and replace with actual explanation of why this is better)
While some complain that go creators have ignored all language research done since the past 30yrs, well, it might be true, but then again you can' create a product or a language which everyone will fall in love with, there are always some or the other use cases or constraints which the creators should consider, and considering all the advantages at least for web development I do not think any language gets close to the advantages which `go` has even if you ignore all that I said above, go is a compiled language which means in production you'll not setup a `JVM` or a `virtualenv` you will have a single static binary! And like an icing on a cake, all the modern libraries are in the standard library, like the `http`, which is a major advantage, which is the reason you can create webapps in golang without using a third party web framework
While there may be some founded complaints that go creators have ignored all language research done since the past 30yrs, you cannot create a product or a language which everyone will fall in love with. There are always some or the other use cases or constraints which the creators should consider. Considering all the advantages at least for web development I do not think any language gets close to the advantages which `go` has even if you ignore all that I said above. Go is a compiled language which means in production, you won't have to setup a `JVM` or a `virtualenv` and will instead have a single static binary! Like an icing on a cake, all the modern libraries are in the standard library, such as the `http` lib, allowing you to create webapps in golang without using a third party web framework.
# 2.1 Hello, Go