Live data from Hacker News

Go best practices, six years in

peter.bourgon.org

61–70 of 207 posts

Re: Go best practices, six years in

#61
post #52

Earlier quoted context omitted.

> - debugging is way harder. Hope you like printf. Can't you use gdb with Go? https://golang.org/doc/gdb

The second you launch a Go routine, gdb becomes useless.

How do you debug then? (I'm not a Go coder, tho I'm familiar a bit with it)

Re: Go best practices, six years in

#62

Earlier quoted context omitted.

Appreciate it was written as tongue in cheek, but I am glad that today a developer can start with Go, test, write code, build, deploy all with Go, whereas nearly every other ecosystem requires additional tools, often external competing tools. Then life becomes about having to learn whole new toolbekt before even coding. Go still keeps it lean, and is great. The fact it does not have hipster dev approved status is als…

Rust has that built in, but managed to be a much more solid language (feature wise).

I don't know, I want to like Rust, but every time I pick it up I feel like I'm relearning C++. It's learning curve is steep, the sorts of applications I write benefit more from solid development velocity and a good concurrency story. I might be wrong, but I get the feeling that Rust really only shines where performance and meticulous control are paramount. I want to like it, but it feels ill-suited to the applications that interest me. :(

Re: Go best practices, six years in

#64
post #26
post #4

Good article on the whole, but I have a few quibbles: > If your repo foo is primarily a binary, put your library code in a lib/ subdir, and call it package foo. IMHO, that's just ugly, uglier than foo/foo or foo/foolib or foo/libfoo. I also think that anything which has commands other than a single-command project which will always be a single-command project (there are fewer of these than one might think …) should p…

> IMHO, that's just ugly, uglier than foo/foo or foo/foolib or foo/libfoo. > I also think that anything which has commands other than a single-command project which will always be a single-command project (there are fewer of these than one might think …) should put all commands, even a single one, in cmd/. It's this kind of inflexibility in the directory structure of ones repo that really turned me off of Go. It's su…

> For instance, there's a ton of Go repositories out there that are not go gettable because the author wanted to put source code under a src directory and hacked that together using make.

Are there? If someone's that ignorant of the language, I don't think I'd want to run something written by him …

> And good luck with organizing any repository that contains multiple languages where go is one of them...go's "code lives at the repository root" doesn't play well with others.

I've actually built libraries which involved both Go & Python without a problem.

Re: Go best practices, six years in

#65

Earlier quoted context omitted.

Oh me too - my setup is usually split screen IntelliJ and iTerm2. But as projects grew larger, (and I wasn't a vim-er) a lot of the tools that come with a full fledged IDE became nice-to-haves (definition-on-hover as source code, click-to-definition, tree and object graph always open, and so on). I know my setup isn't for everyone, but if you're looking for a good Go IDE experience, especially if your projects are of…

As a Java developer that uses Intellij exclusively this is great news. Maybe I'll check out Go more. I really hate using languages without good IDE integration.

I think you'll have a good experience with the integration. Go is the only language I know of where tooling is mostly painless. If you can manage to grok the notion of GOPATH, everything else pretty much just works--even in vim, all you have to do is install vim-go and you get code completion, automatic formatting, jump-to-definition, test execution, coverage reporting, compilation/compilation-error-reporting, etc etc all out of the box (vim-go just wrangles a bunch of programs that provide these facilities, which mean they can also be wrangled for other editors as well).

Re: Go best practices, six years in

#66
post #25

Earlier quoted context omitted.

Check out YouTube conf. talks from the same author, where he shared his experience developing services in Go, while working at SoundCloud. Also, very helpful.

Could you please provide the link?

I'm assuming they are the ones listed here: https://peter.bourgon.org/talks/

Re: Go best practices, six years in

#67

> No statements go by where the object is in an intermediate, invalid state. This seems kind of misleading. Per my understanding of Go, omitted fields in a struct initialization are defaulted not reported as errors. So you're equally likely to be passing invalid state, in the two situations. One pattern I like in Haskell, for this kind of thing, is to define a defaultConfig value that contains typical defaults and wh…

Hopefully you'll combine that idiom with "make the zero value useful" so that omitted fields still give valid behavior.

Re: Go best practices, six years in

#69
post #38

The stages of go enlightenment: 1. Holy crap, this is like coding in early Java days, what the heck were the language designers smoking?! They just ignored everything! Where's my testing framework! DI?! Build system, dependency management?! WTF. 2. Holy crap, this is like coding in the early Java days! This is awesome! I can understand all golang code I read! Everything is so simple and easy. I finally get "less is m…

Well, hundreds of lines of mock structs is probably a sign that there is something very fundamentally wrong with the code. Go, as a language, has nothing to do with it. Testing is one of its nicest features. I only had to improve my testing experience just a bit, like stringifying complex outputs to compare them easily, comparing all of outputs with expected outputs in a single if statement and issuing a single verbose t.Errorf on failure, showing what functions produced what outputs on what inputs and what was expected.

Re: Go best practices, six years in

#70

> No statements go by where the object is in an intermediate, invalid state. This seems kind of misleading. Per my understanding of Go, omitted fields in a struct initialization are defaulted not reported as errors. So you're equally likely to be passing invalid state, in the two situations. One pattern I like in Haskell, for this kind of thing, is to define a defaultConfig value that contains typical defaults and wh…

Hopefully you'll combine that idiom with "make the zero value useful" so that omitted fields still give valid behavior.

Reading on, I see that.

It still breaks down when a zero value is meaningful for a configuration parameter, but means something different than what was done before the parameter was configurable. I think that's probably not super often.

In light of all this, I still don't really see what harm we're avoiding by preferring the inlined struct initialization. I do agree it looks a little prettier, but the article seems to give it a greater import.

Post reply on HN