9 ms·
This article doesn't address one of the biggest benefits I've noticed in switching from Python to Go. I've been using Go for almost two years now. Like OP, I a
by chimeracoder 13y ago
This article doesn't address one of the biggest benefits I've noticed in switching from Python to Go.
I've been using Go for almost two years now. Like OP, I am/was primarily a Python developer. Like OP, my first Go project was a time-sensitive rewrite[0] of a project from Python (tornado) to Go.
Even though I was an experienced Python developer, the Go rewrite was marginally (~20%) faster[1]. But the real benefit came from the subsequent development - refactoring, rearchitecting, and maintaining the project on an ongoing basis. Go was designed to make it easy to scale the maintenance[2] of software, and on this one axis, it absolutely blows every other language and environment I've used out of the water.
For a fresh project, I'd say Go is about 10% slower to write than the equivalent Python[3] for the average case. But the time/cost savings are very quick to come thereafter.
[0] I would absolutely not recommend doing time-sensitive rewrites in general, but that decision was a separate matter.
[1] Some of this is due to the nature of rewrites in general, but the fact that it wasn't slower to use a language I'd never used before says something about the language.
[2] Scaling software development as teams grow is very different from scaling software as users grow.
[3] Assuming comparable familiarity with both languages, which is rarely the case, of course
- aturek 13y agoThis sounds really interesting, but can you elaborate on how Go scales better with maintenance? (disclosure: I haven't fiddled with Go at all yet, so I know nothing about the language itself)
- SpikeGronim 13y agoSeveral things make it easier to maintain: - super fast compile times for fast developer iterations - you can create an interface (set of methods) that your module owns, and apply it to objects created by other modules without recompiling. If you only need one method you can take that one. It encourages decoupling you from your dependencies. - the code has one correct formatting convention and a tool that will auto-format your code - many complex rules for numeric conversions that are implicit in C and cause no end of trouble are explicit and much simpler in Go. - treating concurrency as a series of sequential process connected with channels makes it MUCH easier to reason about.
- Pxtl 13y agoDon't the first 3 apply just as well to python? It compiles fast, and is duck-typed so interfaces are always there and implicit, and the indent-based blocking ends many arguments about formatting.
- dekhn 13y agothe difference is that if you're not careful when you cut-paste indented blocks in python, you can easily change logic.
- mau 13y agoIf you cut and paste probably the misaligned indentation is the least problem. Cut and paste should be avoided if it's not done during a refactoring (so actual moving of code for better design). Beginners usually think Python strong indentation is a weakness of the language. I actually find C++ freedom being more error prone: if (a < b); a = b It's a not very frequent bug, but when it happens it takes you hours to spot. ;)
- maxiepoo 13y agoYes and in Go (and hopefully all curly-brace languages of the future) this is actually a syntax error, you need the braces: if (a < b) { a = b; }
- eternalban 13y agoWould you please expand on [2] please with concrete examples.
- codezero 13y agoI also rewrote a tornado service in Go. The thing I found most surprising was that the length of the program was about the same as the Python version. I had expected it to be quite a bit longer.
- nostrademons 13y agoI'm curious, how does it compare to Java with a good IDE (eg. Eclipse or IntelliJ)? One thing I really missed when I abandoned the Java world and went to C++/Python was the refactoring and formatting tools available in the IDE. I could set it up so it'd auto-format my code on save, so that I could rename methods with a single keystroke, so that I could pull out classes or add getters/setters, so that I could add parameters, etc. I know Go supports some of that through gofmt and go fix, but I'm curious if anyone is both an experienced Java dev and an experienced Go dev and can compare the continued maintenance costs of the two. BTW, I would put the productivity premium of Go over Python at about 50%-2x, not 10%. I did a mid-size (~6 man-months, though much of that time went into interactions with other teams) green-field prototype in Go at Google, and found myself really missing constructs like list comprehensions, dynamic typing, strong support for literal data, ability to treat user-defined types just like the built-ins, etc. I do think you'll make some of that back in continued maintenance - I actually really enjoyed working with Go - but I didn't experience the claims of "Go is just as good as Python for prototyping", as someone with a fair amount of Python experience.
- MBlume 13y agoDoesn't Go come with an executable that reformats .go files to a canonical format?
- nostrademons 13y agoThat's the gofmt tool that we're all talking about.
- micro_cam 13y agoThe availible go ide's are still young but go includes a lot of really nice tooling in the core distribution. The gofmt tool enforces a canonical format for go code and I have sublime text set up (via gosublime) to reformat on save and use the gocode autocomplete/linting daemnon. Gofmt is actually one of my favorite parts about go and I feel that it, along with the simple documentation system and godoc.org save me a ton of time making my code ready for others to read/use. The code base behind gofmt and gofix can also be used for other tools, i haven't felt the need for a powerful refactoring tool but I'm sure one will show up eventually. I do miss list comprehensions and operator overloading but I understand the dev's arguments against those.
- JPKab 13y agoIs there a book or tutorial or blog you would recommend for a Python person to learn Go? I'm certainly interested in what your thoughts are.
- stanley 13y agoHere's a few links you might find helpful. They're not specific to Python developers, though. http://www.golang-book.com/ http://www.golang-book.com/ http://www.golangbootcamp.com/book http://www.golangbootcamp.com/book http://talks.golang.org/2012 http://talks.golang.org/2012 https://gobyexample.com/ https://gobyexample.com/
- chimeracoder 13y agoSure - I actually gave a talk last year on this exact topic. There's an audio recording somewhere, but here's the repository for the slides (which contains a link to the PDF): https://github.com/ChimeraCoder/go-for-pythonists https://github.com/ChimeraCoder/go-for-pythonists
- waterside81 13y agoI wrote about my experience here: http://blog.repustate.com/migrating-code-from-python-to-golang-what-you-need-to-know/2013/04/23/ http://blog.repustate.com/migrating-code-from-python-to-gola...
- ragsagar 13y agoHow does Go makes it easy to scale the maintenance of software?