How I Start: Go (2014)
howistart.org
howistart.org
https://github.com/thewhitetulip/web-dev-golang-anti-textboo...
Go is simple for simple tasks that fit Go type system, and yes the single formatting standard and the linting helps with readability.
Go is a pain in the ass for complex tasks that don't fit go type system, like de-serializing polymorphic data or working with XML. But at the end of the day, the lack of polymorphism in the language makes complex things way more complex than they should be. Finally, Go relies way to much on runtime behavior for a statically typed language.
I find dynamically-typed languages easier to work with when dealing with (de)serialization, it's just that Go isn't too horrible at that to warrant abandoning it and losing out on its other niceties in favor of a different stack.
I mean, everything sucks at something, and Go's type-system isn't....great....but it's "good enough" to where you just kind of curl your lips in slight disapproval sometimes instead of tearing your hair out.
I've met non-technical people who were able to make a webapp in PHP after 6 days with just the standard library and the O'Reilly Head First book.
Maybe I learned Python webdev in a wrong way, so, compared to that, Gonwas a cakewalk.
> for 6-7 months, I was still reading tutorials, and every 6 months a new version of framework would come up
So, according to you, the invention of ONE new python framework caused you to rewrite everything you had been working on? What frameworks did you switch between? Why?
Golang is a popular language now, and there are going to be frameworks coming out all the time. There are already lots of Golang webdev frameworks. Imagine if you were starting with Go now, and you learned something like Revel (https://revel.github.io/) before learning how to make web apps with the standard library. Or imagine you spent 6 months learning a framework and then decided to jump to a new one when another one came out.
Also, from perusing the introduction to your Golang book, it seems like you were lacking knowledge of HTTP and other standards. I find that it's very difficult for anyone to learn web development without at least understanding a little bit about HTTP first. Only once you understand how all web development is the same, can you evaluate the ways that different languages do the job of writing HTTP servers.
No, the thing is, while I was studying Django, I wasn't learning how to write webapps, I was learning the framework. As I said earlier, I might have gone in the wrong way to learn. I didn't find a book which taught me what I wanted to learn, they all either were too abstract or taught a framework, thus, I started to write my guide, which assumes no background knowledge.
> the invention of ONE new python framework
Did I say that?
>Imagine if you were starting with Go now, and you learned something like Revel
The whole point behind my tutorial was to teach newcomers how to write webapps without using a framework.
> Also, from perusing the introduction to your Golang book, it seems like you were lacking knowledge of HTTP and other standards
I don't claim to know each and every aspect of HTTP and other standards, my book was about the journey I had while learning webdev and Go without using a framework, everyday there are new programmers trying to write webservers in Go, and I felt that there was a need of a book which taught by example.
> Only once you understand how all web development is the same, can you evaluate the ways that different languages do the job of writing HTTP servers.
True, with Go, it was no hassle to write webapps because Go has built in http library and it is a compiled language, thus my shift from Django to Go.
No, not exactly, but you complained that "for 6-7 months, I was still reading tutorials, and every 6 months a new version of framework would come up," can you explain what you meant by this? You say you were learning Django, why did you not stick with that? What new frameworks came out that made you stop learning Django?
> True, with Go, it was no hassle to write webapps because Go has built in http library and it is a compiled language, thus my shift from Django to Go.
See, these are the kind of statements I take issue with. interpreted languages are incredibly popular in web development because of how much easier they are to get started with than compiled languages. Not that I think AOT compilation makes a language bad for web development, but you seem to be asserting that Go is better for web dev and easier to learn because it is compiled and has a built in http library (python has one too! (https://docs.python.org/2/library/httplib.html) and if it's too low level for you, the documentation even points you to the open source requests library, which is the standard in the python community).
> As I said earlier, I might have gone in the wrong way to learn.
Yes, this is the point I'm trying to make. You're comparing apples to oranges when you say that Go makes web development easy to pick up compared to Python when you didn't really try to learn web development in Python, you tried to learn a high level framework without knowing anything about HTTP, a recipe for disaster in Python OR Golang (the point I was trying to make by referencing Revel).
2. in his example, `go get github.com/your-username/hello` also automatically compile the thing into a binary in `$GOPATH/bin`. Is that correct?
A lot more people uses $HOME/go as GOPATH. So much so that $HOME/go is the default in Go 1.8.
import "http://www.geocities.com/bla/packagebla"
i.e. I don't want to mention some 3rd party irrelevant company name, and especially its URL in my source code.
And if you start maintaining a redirect on a site you control, what happens when you let the domain die because you never use it?
The amount of HN people who have a personal domain listed in their profile that is dead because life got in the way is surprisingly high (including me until recently).
Right. Either you trust that Github or whomever will always be there or you manage your own domain, or you vendorise and put your dependencies in tree. There are benefits and drawbacks to each approach. It's not magic and we're all adults.
There is no way to avoid doing code changes in order to update the code that was vendored, this assuming that it isn't a binary package to start with.
New uses of go get will not work, but it's not impossible to work this way. Alternatively, you use find . -name \*.go -exec sed -i 's:github.com/coolpeople/coolpackage:gitlab.com/coolpeople/coolpackage:' {} +`.
More about this here https://golang.org/doc/go1.4#canonicalimports
And he/she also don't have do any extra work so that I can keep using the same package names.
As for being upset, not really, unless my boss requires me to use Go, I don't plan using it again.
import "geocities.com/bla/packagebla"
which, IMO, is totally fine, Java has popularized putting some variant of the URL in the package name.For me, it means that all dependencies are declared by origin, meaning you don't need to track where they come from , the origin is the import.
One of the most stupid engineering decisions I've seen in years, imo.
Now explain your side.
Java and Node, for example, don't solve anything - to get something that builds sensibly they both entirely depend on "external service" being always available and enforcing naming (see the leftpad fiasco). C/C++ are the source of the term "dependency hell".
$ go get whois etcd
github.com/coreos/etcd
But no. We need to put that in every freaking file and thus transit from information to noise.https://www.kickstarter.com/projects/2066438441/haunts-the-m...
(Vendoring and package management are different issues)
https://github.com/coreos/etcd/blob/master/lease/leasehttp/h...
What could possibly justify having to use that import line in a sibling package of the same code?
Then don't use a irrelevant company name. Use your own name e.g. rsc.io/pdf . See more here https://golang.org/doc/go1.4#canonicalimports
1) I know exactly where the package came from:
import "geocities.com/bla/packagebla"
vs
import "packagebla"
2) Easy to determine if the package is official, internal, or external (gofmt).
However, what is lacking is a unified vendoring standard. They will address this shortly.
mkdir $GOPATH/src/mystuff
git clone https://github.com/foo/bar
# may be switch to a branch here while you're at it
mv bar $GOPATH/src/mystuff/bar
Now in your Go program import "mystuff/bar"
The whole "URL import" is not a "feature of Go", it's an artifact of "go get", just a tool to make it easier to pull code from github or whatever.1. I know precisely where a package is coming from.
2. When vendored, I know precisely in which directory a package is stored.
3. I actually want to know if a random no-name library is introduced by developers, so I can google it. URL looking import is a nice feature in this case.
I've never encountered anyone -- both online and offline -- who has had trouble with this beyond "huh, I didn't know I had to do that. Duly noted".
Until now, that is. You are making a mountain out of a molehill ... nay, an anthill.
This is the official installation document. If you have problems finding proper tutorials, there is also
which also links to the previous document on install instructions.
It's fine, I can work around it, but it's still quite annoying.
It is not really a big deal, I can overcome it with some simlinks and conventions, but this is not elegant; I hope a model to support this better will be added sometime.
The convincing reason is that you get several automated behaviors in fetching, installing and building this way.
If you don't care for those, you can use whatever path you like for your code, and a custom makefile for building.
Just don't expect "go build", "go install" etc to work.
> Hellogopher: "just clone and make" your conventional Go project
https://github.com/Homebrew/homebrew-core/blob/master/Formul...
url "https://storage.googleapis.com/golang/go1.8.src.tar.gz"
mirror "https://fossies.org/linux/misc/go1.8.src.tar.gz"
version "1.8"
sha256 "406865f587b44be7092f206d73fc1de252600b79b3cacc587b74b5ef5c623596"
This checksum matches the one on the official download page:406865f587b44be7092f206d73fc1de252600b79b3cacc587b74b5ef5c623596
The Golang people could save a lot of headaches and fix whatever they see wrong in the formula so people can continue to use their package manager instead of being reduced to Windows style savagery.
Edit: looks like someone indeed tried to make an issue:
https://github.com/Homebrew/homebrew-core/issues/9272
If I understand, the Go team made the binary package install stuff not in the source tarball. That's doesn't sound like a good idea but they're some smart people; I'm sure they have some reasons. T'woud be nice if they helped bring brew in-line as well.
Either you use query params, or you use a library like gorilla, where you just insert pattern variables into the url.
I'm all for advancement, but this feels like overload. We have each of the big companies promoting their own languages. Microsoft: C# (and other flavors), Apple: Swift, Google: Go, Mozilla: Rust... I'm sure I could keep going, but that seems to be the trend lately. You can't be a big company and not have your own programming language.
So I guess the language changes for each domain. There is no longer the dream of a single language to unite all the plebes! Maybe it was a dream anyways.
F# may be a better comparison.
Historically languages were limited by their compilers and VMs. You ran Java or C++ because it took a large company to come up with a fast enough environment. Now we have the tools and experience that anyone can create a fast enough language in a few weeks.
Also historically, if you wanted your code to run faster, the answer was pretty much always to move to a lower level language. Java too slow? Use C++. C++ too slow? Use C and/or optimize choke points with assembly.
The tooling exists now that we can solve a lot of those same hard problems using languages and tools designed to solve them without reinventing the wheel in C or assembly.
By the way, C# has been around for 17 years.
Does anyone know of a resource like that? I understand it would be different in on each platform but a fun and interesting read either way.
In this case, it sounds like resp is commonly used, so that's not necessarily a problem. But in general, if a line is long enough that shaving a few characters off a symbol helps, it probably should be split up regardless.
https://www.lysator.liu.se/c/pikestyle.html
Quoting:
"Ah, variable names. Length is not a virtue in a name; clarity of expression is. A global variable rarely used may deserve a long name, maxphysaddr say. An array index used on every line of a loop needn't be named any more elaborately than i. Saying index or elementnumber is more to type (or calls upon your text editor) and obscures the details of the computation. When the variable names are huge, it's harder to see what's going on."
I don't agree with everything written therein, and it was written circa 1989. But in practice single letter variable names are used diligently and frequently in Go, they're convenient and don't break readability if you understand the (simple) convention.
For example, maxphysaddr we now write: max_phys_addr. And when it comes to loop indices, using single letter 'i' isn't practically searchable.
Also, our notion of iterators has progressed in the last 27 (gulp) years. Arrays these days are generally too abstract. There's a reason a block of values has been assembled. If they're pixels or bananas, the index can represent that, e.g. for( banana_idx = 0; banana_idx < bananas.num; banana_idx++ )
This is doubly important in blocks of code where multiple types are used, for example, a uint8_t for one index, a unit16_t for another. They need different variable names anyway, so make name them germane to their function.
"Amount to type" and especially "calls upon your text editor" are irrelevant to clarity.
Every modern language should strive to be user friendly. Gone are the days when we were constrained by hardware limitations which caused us to adopt such practices in the first place.
One letter variable/parameter names is a despicable trend. Abbreviated function names are also rather vile in my eyes.
* err, i, req, resp are so common in a lot of Go codebase that they become a convention themselves. So it's not that hard to read. Another example: Javascript's function(e) {}
* If a name is too long, it impedes readability as well, e.g. SimpleBeanFactoryAwareAspectInstanceFactory.
It's a matter of getting used to, leater it's easy and fast to read.
Abbreviations I can think of right now are: w writer, r reader/request, i, j, k, ctx context, resp response, req request, err error, cli Client
see Github project https://github.com/peterbourgon/how-i-start-go
and Twitter https://twitter.com/How_I_Start/status/506510262909030400