
Goodbye Python, Hello Go - eadmund
https://thinkfaster.co/2018/07/goodbye-python-hello-go/
======
tomohawk
One of the biggest benefits of go vs python is that you only manage your
dependencies during build. You end up with a single executable that is easy to
deploy and mostly immune to the deployment of other things. In python, you
have to also worry about deployment. To be safe, you need to carry the vm and
other dependencies with you.

This means you can't just give any python program to someone and have it just
work, unless it's pretty trivial.

~~~
nine_k
Go also carries all its dependencies with it; this is why it produces large
single static binaries.

Python lacks a tool to _painlessly_ produce the same, that is, a self-
contained binary that includes the VM and all the dependencies. Determining
Python dependencies may be slightly tricky, because `import` is an executable
statement, and dependencies may be native-code libraries.

There are several tools for that, but all have their downsides, and none is in
widespread use. Polishing such a tool until it's as simple and fool-proof as
Go's build tool could be quite beneficial for Python community.

~~~
ofrzeta
Why does it have to be a self-contained binary? When you pack everything into
an virtualenv you get more or less the same result, don't you? If you want to
have a single file you can zip it :)

~~~
sacado2
You can deploy an executable on a server just by typing

    
    
        GOOS=linux GOARCH=386 go build foo && scp foo user@server:
    

That's a lot of time saved, especially when you do it on a daily basis, and
not something you can do as easily with virtualenv and such.

~~~
meddlepal
Yea I just do not buy it. How much time is saved? Is it writing an additional
SSH command to extract the file or hitting the up-arrow on your keyboard to
repeat the previously run command?

~~~
sacado2
Not a lot, but when your test environment is on a remote server (because it
replicates the production DB and you can't have that on your dev machine for
security reasons), you tend to do it a lot. Add fast compilation to the mix,
and you have a very productive workflow. `make && zip && scp && ssh unzip` is
way slower than `go build && scp`

------
KaiserPro
First let me state that a language is just a brush with which to paint your
logic. I really don't subscribe to the X is better than Y. I might concede
that x is better than y for certain tasks, but not a sweeping generalisation.

The first point about inconsistent spelling mistakes, I 100% sympathise. I
suffer from this terribly. Pylint and syntastic are a silver bullet for me. I
have been tempted by a more fancy IDE, but I'm so used to vim, I'm
reluctant/scared to change.

Parallelism: I do look over the wall at Go and wish that python 3.x had spent
more time on removing the GIL, but that is old news now.

However I enjoy threading with python(not its limitations), because its so
trivially easy. The Queues primitive saves 90% of the headache. as for ctrl-c
not doing anything set all your threads to daemon
(<threadObj>.setDaemon(True)) When the main thread exits, so does everything
else. Go shines by having built in true parallelism

If I need horsepower, then I have to run multiple processes (not
multiprocessing, that has drawbacks.) which has the annoyance of serializing
and message passing. (but that does mean scaling horizontally less painful
further on). Again, Go really shines here.

Statically compiling thing: YES. This means that I can 90% of the faff with
docker (xyz version not working any more, the build fails) and use a real
scheduling system that runs on real steel(or AWS) and not the omnifaff that is
kubernetes.

~~~
codemusings
> I have been tempted by a more fancy IDE, but I'm so used to vim, I'm
> reluctant/scared to change.

I'm happy to report that JetBrains' VIM plugin is almost flawless (Block-based
editing, window splitting, save/close, it's all where it's supposed to be).

I used to be in the same camp. But if you add a linter and parser and full
blown backend to make lookups for code completion to your VIM configuration
you might as well use an IDE. I've switched to IntelliJ for Java.

~~~
abhishekjha
And they provide a free all pack subscription for open source contributors.
Its nice to see all the features at one place though their pipenv integration
is still a bit shaky[0]. I haven't got a response yet.

[0] :
[https://youtrack.jetbrains.com/issue/PY-30855](https://youtrack.jetbrains.com/issue/PY-30855)

------
k_bx
For those who lack the generics, I just wanted to remind that you can "script"
in Haskell by adding this to your header:

    
    
        #!/usr/bin/env stack
        -- stack script --resolver=lts-12.2
    

and run it as an executable if your machine has stack installed. If not --
compile it with a `stack ghc --resolver=lts-12.2 ./file.hs` and you'll have a
`./file` executable. No project creation, no need to list the dependencies.

~~~
exceptione
Good trick! Do you also know the Turtle library? I just got across it, and it
looks like a neat shell library from the outside.

------
gsibble
I've written in Python for ~13 years and I'm really enjoying Go. It's fast and
its libraries (the few there are) seem to make a lot of sense. I don't think I
would use it for daily scripting like the author, but for a large new project
I would definitely pick Go over Python now.

~~~
lmm
Try an ML-family language (e.g. OCaml, F#, or Rust) if you haven't already.
You get the best of all worlds: expressiveness, safety and speed.

~~~
doteka
I like the expressiveness of Rust in theory, but for the programs I write I
don't feel like I get sufficient payoff for fighting the borrow checker, as
compared to writing in Go. Would I be correct in saying OCaml is pretty much
Rust without the borrow checker? I have no prior experience with the language.

~~~
petre
Dlang is also very nice if you like Algol style languages. You can get
productive in it pretty fast, just like in Go, but it's expressive, it's
garbage collected by default and you don't waste time fighting the compiler.
Also the code compiles as fast as Go with DMD and LDC. I havent tried GDC.

[https://tour.dlang.org/](https://tour.dlang.org/)

~~~
ben-schaaf
Plus you get templates and CTFE, which are both awesome. Though if you're
doing web stuff I've found D compile times to not be so great anymore,
especially when diet templates get into the mix.

------
arendtio
Does someone know a ressource where I can easily learn how to switch from Bash
to Go?

To give some context: When it comes to serious programs I use Go already, but
often I just want to code a little script to watch a website for changes for
example:

    
    
      #!/usr/bin/env bash
      url="https://example.com"
      mem="memory.txt"
      oldsum="$(cat "$mem")"
      newsum="$(curl -sL "$url" | sha512sum)"
    
      if [ "$oldsum" != "$newsum" ]; then
        xmpp_notify "$url changed"
        echo "$newsum" > "$mem"
      fi
    

I haven't tried it yet, but in my mind it feels like writing such a program
would be more time consuming/complex in Go than writing it in bash.
Neverthelss, I feel like Go is overall a much better language than Bash (with
all those quotes), so I would like to transition to writing more short
programs in Go and for that I would like to learn how to do things like
reading/writing/grepping files as easily in Go as I do it in Bash. Any idea if
someone wrote some hints together already?

~~~
IshKebab
Writing a program like that would not be too difficult in Go. It's something
like this:

    
    
        func main() {
          url := "https://example.com"
          mem := "memory.txt"
          oldsum, err := ioutil.ReadFile(mem)
          if err != nil {
            log.Fatal(err)
          }
          
          // Download URL
          resp, err := http.Get(url)
          if err != nil {
            log.Fatal(err)
          }
          defer resp.Body.Close()
          body, err := ioutil.ReadAll(resp.Body)
          if err != nil {
            log.Fatal(err)
          }
          
          // Hash it
          newsum := sha512.Sum512(body)
          
          if oldsum != newsum {
            err = exec.Command("xmpp_notify", url + " changed").Run()
            if err != nil {
              log.Warn(err)
            }
            err = ioutil.Write(mem, newsum)
            if err != nil {
              log.Error(err)
            }
          }
        }
    

Don't listen to the naysayers. Go is fantastic for scripts like this - it's
really good at network stuff, has a ton of built in functions, etc. And you
get actual robustness and error checking that isn't a complete joke. Look how
many ways your Bash script could fail! That's fine if you're literally
watching the output with your eyes. If not it's going to cause issues when
`curl` fails for example.

The only downside really is that you have to compile the Go code, which is
fast but not as fast as just interpreting a Bash script (the first time).

Another possible issue is executable size - if you have a lot of Go scripts
they may take up a fair bit of space.

I wish Go had an interpreter / JIT mode for scripts.

Edit: Before someone says "but that's 3 times longer than the bash code!"
please write the _equivalent_ Bash code that has proper error checking.

~~~
boris
Just add this as a second line?

    
    
      trap "exit 1" ERR

~~~
majewsky
I think you mean:

    
    
      set -euo pipefail

------
greyman
> I’m not a fan of full blown IDEs that require their own configuration.

Hmm, but those IDEs actually do solve most of the problems author has had with
Python. If one regularly code in Python, spending a few hours configuring the
IDE is justifiable. I for example never write scripts outside the IDE, because
why?

~~~
kungtotte
_Note: I like Python, so this is me playing devil 's advocate here._

If you _need_ an IDE to solve common pain points of a language, isn't it fair
to say that another language which lacks those pain points is a better fit for
you? Using an IDE to aid you, to smooth things out and allow for more rapid
development and better workflow is one thing. Being forced to use one because
the language is lacking is a bad look on the language!

~~~
jacobush
You could also say that this attitude holds us back. What if Smalltalk had
only been accessible from _vi_ back in the day, would Smalltalk have been as
appreciated? I think not.

------
SjuulJanssen
Some issues:

\- I make stupid mistakes in Python constantly. I misname a variable or a
function or I pass in the wrong arguments: Try mypy

\- If the task is IO bound: Threads are the wrong the answer to that. You're
going async by using Golang, why not in python?

\- With Python, I have to ensure all the packages I need are installed on the
remote machine: pipenv Like slezyr mentions

\- Consistent Styling: Try autopep8 or black

\- Intellisense: I would say "use Pycharm" but vscode is getting better I
heard

~~~
raverbashing
Pylint is a bit hard to configure, use Prospector

Prospector does a better job and it prevents you from wasting time with what
essentially are stylistic choices and BS like a hard 80 chars limit per line
(remember, A Foolish Consistency is the Hobgoblin of Little Minds)

And yes, yes, automated stilling tools are better

Intelisense is needed but even the standard vim autocompletion plugin does an
ok job

------
vortico
This is like saying "Goodbye car, hello airports!" If your needs change, then
of course your favorite solution may change.

------
ivan_ah
This makes me want to try Go, though I wonder how long it would take to
develop the same "fluency" and knowledge of which library to use. It would be
exiting to have things run fast though...

One minor plug `pyflakes` is very good for basic checks for mistyped variable
and missing imports, etc. It's not "smart" and doesn't check type consistency,
but very useful to catch stupid mistakes.

~~~
dilap
I went from Python to Go; Go is an amazingly simple and quick to learn
language and ecosystem. Give it a try -- you'll probably start to feel
proficient a lot faster than you'd think.

------
slezyr
> I like having a single binary. I usually run code on EC2 machines to give my
> scripts closer network proximity to S3 and to our database. With Python, I
> have to ensure all the packages I need are installed on the remote machine,
> and that one of my coworkers hasn’t installed anything conflicting.

pipenv

------
hellofunk
> I make stupid mistakes in Python constantly. I misname a variable or a
> function or I pass in the wrong arguments. Devtools can catch some of these,
> but they usually require special setup. I’ve never been able to configure
> pylint easily, and I’m not a fan of full blown IDEs that require their own
> configuration. The worst is if you mistype a variable that’s hidden behind
> conditional logic. Your script might run for hours before triggering the
> error, and then everything blows up, and you have to restart it.

This this this, a million times this. I work mostly in Clojure where such
problems are equally as bad, maybe even more so. Dynamic, elegant languages
can feel liberating in so many ways, but there are significant workflow
drawbacks that get me nearly every day.

~~~
falcolas
First off, I get that it's unfortunate they aren't detected by Python itself
in some form of compile step, but that's a cost of using a dynamic language.

But they don't use the tools created to catch these kinds of errors, and
complain that they aren't protected against these errors? There's a fairly
large disconnect there. Hell, I have protection against this built into my VIM
install. Not running these basic tools is tying a hand behind your back.

~~~
hellofunk
Are you talking about mypy?

~~~
falcolas
No: python-mode

[https://github.com/python-mode/python-mode](https://github.com/python-
mode/python-mode)

------
JoJoJoboop
I've been using Go over python for a couple months now and so far it has been
incredibly effective. I never really liked Python's syntax so it's nice to go
back to something c-ish.

------
Alir3z4
XAR lets you package many files into a single self-contained executable file.
This makes it easy to distribute and install.

[https://github.com/facebookincubator/xar/](https://github.com/facebookincubator/xar/)

Then just build your XAR executable with:

$ python setup.py bdist_xar

------
ausjke
Python is regularly ranked to top 4 programming language for a reason, Go has
a long way to catch up I think, if it ever happens.

I recently started using python as the primary language, the more I use, the
more I like it.

Go's put everything in a static binary has its pros and cons.

------
luord
I'm pretty sure I've read this same article, give or take a few words, many,
_many_ times before, only replacing the two languages being compared.

This bores me, probably because I find everything to be the exact opposite
(except for parallelism, I'd be foolish to pretend Go isn't better in that
area) but specially because I find Go to be an _ugly_ language to write. The
error handling is only the top of the can of worms.

Python, in comparison, is a delight to write and specially to read (when it's
well written).

In short: Oh, terrific, another one.

------
littlestymaar
Related: [From Python to Go and Back
Again(2015)]([https://docs.google.com/presentation/d/1LO_WI3N-3p2Wp9PDWyv5...](https://docs.google.com/presentation/d/1LO_WI3N-3p2Wp9PDWyv5B6EGFZ8XTOTNJ7Hd40WOUHo/mobilepresent?pli=1#slide=id.g70b0035b2_1_168))

And the HN discussion
[https://news.ycombinator.com/item?id=10402307](https://news.ycombinator.com/item?id=10402307)

------
rajangdavis
Are there numpy/pandas/matplotlib equivalents in golang?

~~~
rajangdavis
Looks like the following are equivalents:

numpy - [https://github.com/gonum/gonum](https://github.com/gonum/gonum)
matplotlib - [https://github.com/gonum/plot](https://github.com/gonum/plot)
pandas - [https://github.com/kniren/gota](https://github.com/kniren/gota) (API
not finalized)

------
iamleppert
If most of your use case is copying s3 files to and fro, maybe doing a bit of
transformation what does it matter what language you use? You could deploy
some python or even JavaScript code to lambda and get the job done faster than
you could with Go. From a performance perspective compiled languages only win
in some very niche cases these days (mostly cpu bound tasks that can’t be
distributed and require low latency).

------
crdoconnor
Re: gofmt - python has black now. It's excellent.

Pylint solves the undefined variable issue, but it is annoying as hell and
_always_ requires configuration. I wish there was a linter for python that
didn't care about 80 character limit and was careful not to drown important
errors with unimportant stylistic tics.

~~~
fermigier
Black is excellent ideed, and solves the problem of having code compatible
with PEP8 once and for all.

flake8 is a linter that doesn't need much config, and you can config it to
give you only "serious" errors and not stylistic issues.

I gave a talk on these subjects last year at the Paris Open Source Summit:
[https://speakerdeck.com/sfermigier/python-quality-
engineerin...](https://speakerdeck.com/sfermigier/python-quality-engineering-
a-tour-of-best-practices) (NB: Black didn't exist yet at the time).

~~~
crdoconnor
flake8, like black, shouldn't really require any config on most projects yet
annoyingly it always requires at least a little. I really would switch to
another tool in a heartbeat if they could just fix that.

Ideally instead of needing to be told whether to only show "serious" errors,
for instance, it should just give you a project "score" (sum of the errors x
their severity) and show the top 20 or so errors in order of importance and by
default it should _never_ exit with error code 1 with just stylistic errors
unless explicitly configured to do so.

~~~
shloub
Have you tried pyflakes?

~~~
crdoconnor
No, and I think you just made my day. Thanks!

Or rather, I'd vaguely heard the name but I erroneously thought it was just
another flake8 type thing.

~~~
camel_Snake
pyllama is another project in the same space which I like. It uses pyflakes
under the hood.

[https://github.com/klen/pylama](https://github.com/klen/pylama)

------
therealmarv
Goodbye plenty, matured, well tested libraries and frameworks and big
community. Hello go.

(Nothing against golang, just wanted to point out it's not that easy for every
usecase).

~~~
djstein
So much this. No one is writing large production applications without some
sort of imported library. Go simply has not been around long enough or had
enough users to mature. For all of the pros Go has (not even mentioning the
cons) they seem miniscule compared to what we give up switching to it. It has
always sounded like the hot new fad and not a stable thing. Especially with
daily articles like coaxing people into using it.

~~~
majewsky
Exactly! It will be many more years before big mature projects like
Kubernetes, Docker or CockroachDB would consider switching to Go.

~~~
therealmarv
This are all sort of very close to system frameworks itself. I would never
write something like that in Python. This is a good example for golang.

------
nhanhi
Archive URL: [http://archive.is/smcWh](http://archive.is/smcWh)

------
f00_
What do Go users think of Scala? Seems like the alpha language

------
finnmagic
“Python is much more flexible.”

------
RickJWagner
Wow, that seems like a pretty big jump. Good for the author.

------
tanilama
Revenge Post.

------
paulie_a
> I make stupid mistakes in Python constantly. I misname a variable or a
> function or I pass in the wrong arguments.

> Unit tests would catch most of these, but it’s hard to get 100% code
> coverage, and I don’t want to spend time writing unit tests for a one-off
> script.

Sorry, I actually do like golang but this is telling of a bigger issue.
Someone else is going to have to delete/fix it

