4 ms·
Most of these mistakes are mistakes for any language you write in.
by shwouchk 11y ago
Most of these mistakes are mistakes for any language you write in.
- kzhahou 11y agoThese specific mistakes are useful for new Go programmers. For example, knowing that a pointer-to-slice is (usually) useless.
- pcwalton 11y ago"Don't use a Web framework" (#1), "use panics wisely" (#2), "be careful when reading from request.body more than once" (#3), "be careful of hidden allocations from pointers-to-slices" (#5), "be careful with the surprising behavior of naked-return-implies-return-0 feature of Go" (#6), and "be careful with the interactions between mutation and shadowing" (#7) are all Go-specific. Among popular languages, issues #5, #6, and #7 apply only to Go.
- TheOtherHobbes 11y agoYou may have an off-by-one error. :) Otherwise you're right - but all languages have sharp edges. I'm using Go on my current project and I've gotten a lot further a lot more quickly and with better performance and reliability than I would have using Django, Rails, or Node. Because I'm not in a hurry I thought it would be fun to write a simple custom server/router/middleware bundle around net/http without using any 3rd party packages. From a cold start it all turned out much easier than expected, and so far the whole thing is under 500 loc. Being careful around a few sharp edges seems like a small price to pay.
- shwouchk 11y ago1) Be judicious regarding your choice of tools 2) Be careful with signalling errors 3) Don't read twice from a stream and expect the same data 4) Don't write SQL? 5) Understand pointers 6) Make it easy for readers of your code 7) Understand Scoping 8) Don't use objects concurrently unless they were designed for it 9) Keep track of which versions of dependencies you use
- reitanqild 11y ago"Don't use a web framework" definitely isn't something I would tell developers. I really think good web frameworks is one of the reasons why the web has progressed so quickly the last ten years.
- peterevans 11y agoI don't think the post here is actually asserting not to use a web framework; just that you should not use a specific framework, named Revel, that aims to be Rails-esque. It brings up an interesting point for me about what is really possible (or desirable) in a framework written in a statically-typed, compiled language like Go compared to a dynamically-typed, interpreted language like Ruby.
- acheron 11y ago"progressed"
- jerf 11y agoIn Go, "don't use a web framework" translates to something like "net/http is already a 'web framework' much like web.py or other 'minimalistic' frameworks". Unlike, for instance, Python, where you "have to" use a web framework because the standard library doesn't ship with much (http.server is too basic on its own [1]), the base net/http is enough for many non-trivial usages. (Of course Python has a few dozen good 3rd-party choices.) [1]: https://docs.python.org/3/library/http.server.html https://docs.python.org/3/library/http.server.html