Why you should learn Go (especially if you are a Python developer)

Why you should learn Go (especially if you are a Python developer)
0

#1

You get almost zero runtime errors. If your program is wrong, it won’t compile. If you use Python, how many of your production-crashing errors are AttributeError or TypeError? Just can’t happen in Go. The most likely runtime panic you’ll encounter is an index error because you were lazy and didn’t check the length before trying to access something.

Deployment is as easy as rsync or scp. Nothing to pip install. All the dependencies are baked in. No need to have gcc on the prod machine because you want to pip install something that has to compile. No need to install PostgreSQL on prod so that pip install psycopg2 will work, since it needs access to pg_config.

Writing code for non-techie friends and family is as simple as giving them a single binary. They don’t have to have Python installed on their system (and forget about it if your program uses something outside the standard library).

The concurrency is amazing. You can actually do multiple things simultaneously, or have multiple copies of a function running. Parsing data? Web scraping? Consuming APIs or RSS feeds? Do it all at once! If you use Django and Celery, imagine having a single binary that does all they do and more – and can even listen on multiple ports simultaneously (for websockets, perhaps) all at the same time.

Smaller, simpler language.

Compiling to a static binary! Yes, I know this is kind of a repeat of deployment and sharing with friends, but I really can’t oversell this. My PATH is bursting with command-line utilities I’ve written and which make my daily life simpler. Sure, many of them could have been written in bash or Python, but these are on a shared drive and guaranteed to work on all my computers without any dependencies. Plus the speed and concurrency benefits…

Speed! In my own side-by-side testing, most things run 4x - 10x faster. That’s from a couple of years ago when I was new to Go and wrote my Go code to mirror my Python code for a “fair” comparison (and no concurrency).

Jobs! There are relatively few Go developers in the world compared to Java, Ruby, and Python. If you learn Go you will be in more demand. I get contacted regularly because of the Go on my LinkedIn profile and in my GitHub repos.

Community! The go-nuts Google Group has the smartest, most mature group of people I’ve encountered in a tech mailing list in my life. They’re helpful and many have deep, old knowledge that they are willing to share with anyone who asks (nicely).


Feel free to ask me any questions about Go and I’ll answer if I can. If you want to post bits of Python and discuss how they’d look in Go, that could be fun, too. Maybe some of those could spin off into their own topics on this forum.

Happy Wednesday!

ShawnMilo


#2

Hi, ShawnMilo

Can you suggest any good Golang books / online courses for Python developer to start with? I would love to try Go - a little bit tired of dynamic types = )

P.S.: Golang mascot is awesome :grin:


#3

Tour of Go -> I just finished it yesterday, it’s a nice online tutorial and intro to the language

Next I’ll go through the online Effective Go

My colleague bought himself the book called The Go Programming Language and he only talk good of it so far.

I’m coming from a C language so many things are familiar. My opinion is that Go is what C should’ve evolved in.


#4

@lancelote: The suggestions by @pieterlouw are perfect. That’s exactly what I would have said, but he beat me to it.

The tour is a great place to start, and the book mentioned is written by some impressive people. It’s the one book I’d recommend as “the” book.

Effective Go is something you should read, but I’d hold off on it at first. I think you’d get more out of it if you had a couple thousand lines of Go written first.

The only thing I’d add to @pieterlouw’s suggestions is to do the tour first, then start off with a small personal project in mind. Don’t just go reading the book or other documentation and try to absorb it. Apply it as you go along, make plenty of mistakes, but most importantly build something (or many small somethings) as you go.

Also, you’ll be referring to the stdlib docs a lot. So it’s good to know where they are. You should probably poke around in them just to see what’s what, especially in places like fmt, io, io/ioutil, os, os/exec, path, path/filepath, strings, and time. Just do a quick read-through of all the functions that exist. That will save you from rolling your own later, and help you find them more quickly when you need them. If you’re used to another language you might expect a function to be in one place, not find, it, and write your own. Knowing it exists somewhere will save you time later.


#5

@ShawnMilo @pieterlouw Thanks for answers!

But I have another question = ) What IDE to pick?

It seems there’s no really good polished specialised IDE for Golang right now, a lot of people suggest Atom with plugins, but I hate it’s slowness. I really love JetBrains products, did you try Golang plugin for Intellij IDEA? Is’t such complex IDE an overkill for Go?

Vim +plugins is also a popular variant, but I’m not sure it’ll provide typical IDE goodies like decent autocompletion, “go to defenition”, debugger, syntax validation on the fly and so on.


#6

@lancelote: See vim-go. You can do tons of stuff with it. Atom with Go plugins has been just fine for me, so I don’t know why you’re having a problem there.

Don’t get caught up in trying to make your environment perfect before you do anything productive. You can spend the rest of your life playing with tools. You don’t need an IDE. You don’t need code completion. You don’t need a debugger. You don’t need live syntax validation. Go is a small, simple language. You don’t need a robotic nanny watching your every keystroke. The compiler alone will keep you in line.

You don’t even need syntax highlighting. Rob Pike (one of the creators of Go) famously doesn’t use or like it. If you disable it you will probably find that you won’t even notice by the end of your first day. I didn’t.


#7

This is just the thread I needed. I am using Python for some time now, mostly for automating repetitive tasks (I am too lazy to do them, so I wrote my own scripts :D). Just recently I discovered Go and poked around this online book: https://www.gitbook.com/book/astaxie/build-web-application-with-golang/details

It kinda pulled me in since the syntax seems like it’s half python and half C. I also like the ability to create your own modules and use them in any project you want.

So my questions now are:

  1. How fast is someone able to learn it? I know this differs from person to person, but I am still wondering how fast were you able to start writing useful programs. I do have some experience with Python, Js, Ruby.

  2. I am currently deciding between Django, Node and Go for my next web app (I already have some experience with Ruby on Rails). Since I don’t really like Javascript that much (I would prefer to use something else for server side, all those brackets and semicolons… sigh), I am leaning towards Django or Go. Go seems quite interesting, but documentation for creating web app with Go is a bit hard to understand, with lots of weird syntax in comparison to Django. What is your experience with Go for web apps? Is it easy to create something, or you need arcane power to build a solid app? Are there some libraries for this task, or do I have to write everything from scratch (reinventing the wheel).

Writing code for non-techie friends and family is as simple as giving
them a single binary. They don’t have to have Python installed on their
system (and forget about it if your program uses something outside the
standard library).

^^ this is just amazing. I hate it when someone ask me if he/she could use the software I have written, and then I have to explain everything in detail how to install Python and all the necessary libraries.


#8

@GreatDanton

Thanks for the reply! For reference, I should say that I did Django professionally for over six years, went to four DjangoCons, contributed to Django (I’m in the AUTHORS file), and built systems for a startup which became successful in Python and Django.

Having said that, I’d never use Django again if given the choice. I’d use Flask if I had to use Python, and I’d use Go whenever possible. As an aside, if you want to hear an opinion I agree with regarding Flask vs. Django, see this and search for Trey Long and read his comment.

With Go, you don’t need a framework. You may use some third-party libraries here and there, but you pull them into your own project, instead of the framework dictating your direction. Also, the built-in concurrency makes your web app perform really well. You don’t even have to do anything to get concurrency. Check out the code I wrote here for a stupid-simple Go web app.

To answer your questions, you can pretty much learn Go in about a day (do the tour, get fairly decent at it in a week or two, and within months you’ll be cruising along like a pro.

Also, if you want some help getting started let me know. I’d be happy to help one-on-one.

Shawn


#9

how productive can one be with Go? Stuff like activeadmin and devise have me stuck on rails.


#10

I don’t know anything about Rails, or what activeadmin is, but you can certainly be very productive with Go. Projects like Docker and SyncThing are built in it.

I forget who said it, but I’ve heard it said that “Go is 90% as easy as Python, and 90% as fast as C.” From everything I’ve heard, Python and Ruby aren’t all that different in most ways, so that should apply equally to Ruby.

  • give it a chance
  • don’t expect it to be Ruby (or Python) – learn “the Go way” and see how you like it.

I refer you to this excellent answer from the Go FAQ.

Happy Friday!


#11

The best resource to learn Go is https://www.youtube.com/user/toddmcleod. You will get everything there, from basic Go, all the way to building several complex web applications.


#12

Hi ShawnMilo,

Great post, I also have Go on my radar as my next language :slight_smile: @GreatDanton when I decided to make web app in Python I also had this dilemma, Flask or Django. So first I started with Django tutorial and documentation and it was dreadfull, really :frowning: Then I tried Flask, started here: http://www.fullstackpython.com/flask.html and little by little started building my app ( it’s still work in progress). And really Flask is big because it’s so small :smiley:


#13

I don’t know, it’s not even under the top ten yet.:neutral_face:
http://www.tiobe.com/tiobe-index/


#15

Oh yeah there are some more!

http://trendyskills.com/

http://pypl.github.io/PYPL.html

http://redmonk.com/sogrady/2016/07/20/language-rankings-6-16/

http://stackoverflow.com/research/developer-survey-2016