refactoring in Go – rather pleasant actually…

I’ve just finished refactoring a large Go program, and the process was rather…. pleasant.

Static typing catches all those obscure errors I wouldn’t think about in a scripting language (Python, Perl, Ruby, etc). My process is:

  • type :make in vim (I have a dummy Makefile in my Go project just for vim)
  • vim jumps cursor to error (vim quickfix list)
  • “oh, I shouldn’t do that” – fix (type type type)
  • start again

Finish rather sooner than expected, run tests, smile in knowledge program is working properly.

Update

To quickly setup the make command for Go, type this in a Vim window:

:setlocal makeprg=go\ build\ \.

Or even better configure vim via your ~/.vimrc, for example:

autocmd BufRead *_test.go setlocal makeprg=go\ test\ \.
autocmd BufRead *.go setlocal makeprg=go\ test\ \./..

Thanks Martin for the comment!

Tags: , , , ,


Share This


 


3 Responses to refactoring in Go – rather pleasant actually…

  1. Hmm how about this :)


    cat <>~/.vimrc
    autocmd BufRead *_test.go setlocal makeprg=go\ test\ \.
    autocmd BufRead *.go setlocal makeprg=go\ test\ \./...
    EOF

    :)

    • Hey thanks Martin! I’m not particularly worried about the Makefile, as it’s actually real for the project I was thinking about (handles build server, builds a .deb, etc). But handy to know for future Go projects :-)

  2. haha my <<EOF>> was eaten by the blog engine :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>