31 Aug 2014 : Writing Python in Go

Know the thing where you switch from one language to another and you’re kind of still idiomatically writing the old language, even if you’re typing the syntax of the new one? I’m enjoying Go, but I’m having to force my brain to stop thinking Pythonically.

The last syntax muscle memory I can’t get around is for loop syntax: I keep typing

for thing in things

instead of

for thing := range things

Adding one extra compilation round every time eventually got too much: I added a vim autocorrect:

autocmd FileType go iab in := range

Now every time I use the word “in” in a .go file, vim will change it to “:= range”. Which means I’m guaranteed to send at least one stupidly autocorrected comment for review.

Go’s error checking gets tedious too. I added this:

autocmd FileType go iab cnil if err != nil {
      \<CR>return err
      \<CR>}

Now, every time I type “cnil” it magically turns into

if err != nil {
    return err
}

Lazy? Very lazy :-)

Comments