226 points · by ianrtracey · 9y ago · 121 comments
https://github.com/thewhitetulip/web-dev-golang-anti-textboo...
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.
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.
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.
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.
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 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.
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
More about this here https://golang.org/doc/go1.4#canonicalimports
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.
One of the most stupid engineering decisions I've seen in years, imo.
(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?
https://www.kickstarter.com/projects/2066438441/haunts-the-m...
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.
By the way, C# has been around for 17 years.
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.
F# may be a better comparison.
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.
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.
* 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.
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.
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
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.
see Github project https://github.com/peterbourgon/how-i-start-go
and Twitter https://twitter.com/How_I_Start/status/506510262909030400