11 ms·
Go Proverbs: Simple, Poetic, Pithy
- sleepychu 11y ago"A little copying is better than a little dependency." I like this but how do you protect yourself against growing into a lot of copying?
- pjmlp 11y agoApparently go generate https://blog.golang.org/generate https://blog.golang.org/generate
- shurcooL 11y agoDon't do a lot of copying.
- falcolas 11y agoPersonally, I use the rule of three. If it's copied three times, refactor it into some form of dependency. At that point, you should understand the use case, and should be able to create a reasonably designed API.
- krishicks 11y agoWhen doing this, be wary of what a friend of mine calls "misfactoring", an example of which being where you take three very similar, very readable bits of code and convert them into a single, parameterized mess that isn't understandable at all.
- Dawny33 11y agoJust in case you haven't read the footer text: The proverbs are based on this awesome talk by Rob Spike: https://www.youtube.com/watch?v=PAAkCSZUG1c https://www.youtube.com/watch?v=PAAkCSZUG1c And for new proverb ideas, you can open an issue here: https://github.com/go-proverbs/go-proverbs.github.io/issues https://github.com/go-proverbs/go-proverbs.github.io/issues
- erikb 11y agoThe video seems much more reasonable for sharing, since it also explains something to non-Golangers. Thanks.
- hyperliner 11y agoRob Pike, not Rob Spike
- kzhahou 11y agoRob Spike sounds like his alter ego, where he goes around giving talks on how duck typing is the way to go, and the top goal of a programming should be to express yourself in as few keystrokes as possible.
- AnimalMuppet 11y agoDuck typing is the way to... go? If you did that on purpose, nicely done.
- soveran 11y agoFor the original go proverbs, see https://en.wikipedia.org/wiki/Go_proverb https://en.wikipedia.org/wiki/Go_proverb.
- howeman 11y agoOr http://senseis.xmp.net/?GoProverbs http://senseis.xmp.net/?GoProverbs
- gamesbrainiac 11y agoI like the Zen of Python more.
- yahyaheee 11y agoYeah I think the zen of Python is stronger, but it's also at a higher level
- thomasahle 11y agoI like them both. Simple lists like these, weak as they may seem, are often a great help when balancing tradeoffs in actual code, I find.
- weberc2 11y agoYeah, but I don't think Python adheres very well to its own zen. I actually think Go follows it better. :/
- distrill 11y agoI like so much about go, but I think the gopher is so god damn ugly.
- icebraining 11y agoWhile I don't agree, I do have to say that Plan 9 did get a much better mascot in the form of Glenda.
- ptrkrlsrd 11y agoAdd some instrumentals and this becomes Radiohead's "Fitter Happier" anno 2016
- buro9 11y agodefer resp.Body.Close() That's almost a proverb by itself.
- omginternets 11y agoSince you mention it: when is it necessary to close the response body?
- deleted 11y ago[deleted]
- buro9 11y agoAny time you managed to get a response you must close the body via a defer resp.Body.Close() And if you're using json.Decoder on the response body then it's worth noting that if you know you're only receiving a single JSON object then draining the remainder of the body will allow connection re-use as otherwise the connection will be closed and not re-used: https://github.com/google/go-github/commit/e0ff7111b024fda991e457d975e0b73e1380f05f https://github.com/google/go-github/commit/e0ff7111b024fda99...
- omginternets 11y agoEven if I don't read the body?
- buro9 11y agoEven if you don't read the body.
- PixZxZxA 11y agoComing from Python, Go seems to be a pretty nice language. Is it worth giving it a shot?
- erikb 11y agoIt is at least as good as Lisp. Even if you never use it in a real project, you will still grow as a developer. I just did some Hackathons and tutorials and have a totally different understanding of what programming can be.
- zdkl 11y agoI hate April 1st because I can never tell when people are joking.
- ihsw 11y agoDoes it matter? You may find their advice useful regardless of their intent. Personally I don't have enough time or energy to determine someone's intentions, I just position myself to be guarded against ill-intent.
- MehdiHK 11y agoExactly my thought.
- erikb 11y agoDidn't even know that it was April 1.
- omginternets 11y agoI came from Python, so here are my two cents: The Good: - Go is a simple language. Going back to Python, I sometimes wish the language was a bit less batteries-included. (Incidentally, I've started to enjoy Lua a lot) - Go's compiler is fast. It's slowed down a bit starting with 1.5 as they rewrote the core compiler in Go, but apparently 1.7 will reclaim much of that speed. In 1.5, I could compile and run with `go run mything` faster than it would take to spin up ipython. - I've come to appreciate interfaces much more than classical OOP. - The ecosystem is great. The Bad: - I hate GoDoc. I tried to like it, but it's essentially a list of function signatures with a near complete absence of examples or clear instructions. The documentation culture in Python is much better, IMHO. - Channels are kinda slow. They're fast enough for almost anything network-related, but you should still use them conservatively. The Different: - Error handling in Go is the complete antithesis of error handling in Python - `panic` is not `raise`. Donc use panic/recover for flow control. - Blocking calls are perfectly okay. A few suggestions: - WRT interfaces, it's generally good to accept interfaces as function arguments wherever practical. Conversely, it's generally good to return concrete types from function calls, wherever practical. (See: https://youtu.be/29LLRKIL_TI https://youtu.be/29LLRKIL_TI) - Go excels at networking. Use Go instead of Twisted/asyncio and I think you'll be convinced.
- erikb 11y agoI wish people would be more clear about what they mean: http://senseis.xmp.net/?GoProverbs http://senseis.xmp.net/?GoProverbs I.e. write "Golang" instead of "Go"
- am185 11y agolove the proverb: Don't panic.
- sebringj 11y agoI like Go but I get an uncomfortable culty-vibe from this posting. Also, if we could just title our blogs with "Interesting, Relevant, Engaging" so everyone would read them would be so much easier.