Thursday, July 21, 2016

Updating VIM for Go (Golang) Development

Since my last post, setting up Vim for Go development is not only easier but also makes developing with VIM much more powerful.  Just a single plugin, vim-go, is all that is needed for the Go-specific stuff and a host of new tools is now available to handle things like refactoring, linting, error checking, and more.

Go Tools

Make sure that you have Go installed and then get the various Go tools.

goimports

Go provides a lot of use packages that can be imported but it doesn't like it when you import a package and not use it.  Goimports will automatically insert the right imports for you by looking at your code and will remove unused imports from your source.  It's a great time saver!

go get golang.org/x/tools/cmd/goimports
godef

Godef lets you jump to the location where a symbol is defined.

go get -v code.google.com/p/rog-go/exp/cmd/godef
go install -v code.google.com/p/rog-go/exp/cmd/godef
golint

Golint will lint your source and warns you of potential issues.
go get github.com/golang/lint/golint
gorename

Gorename helps to refactor Go code.

go get golang.org/x/tools/cmd/gorename
errcheck

Errcheck checks your code for actual errors that isn't just lint issues.

go get github.com/kisielk/errcheck
gocode

Gocode provides autocomplete of your Go code.  When combined with vim-go and YouCompleteMe plugins, it allows autocomplete to appear as you're typing.


go get -u github.com/nsf/gocode (-u flag for "update")
It's a bit different for Windows so follow the instruction from the link for more details.

gotags

Gotags generate tags for Go code.  Combined with Tagbar, it will provide a pretty display of the tags in your code.

go get -u github.com/jstemmer/gotags
Guru

Guru is a tool that integrates with editors to help it understand Go code.

go get golang.org/x/tools/cmd/guru
go build golang.org/x/tools/cmd/guru

Oracle (Deprecated and replaced by Guru)

Oracle is a source analysis tool for Go program.


go get code.google.com/p/go.tools/cmd/oracle

Vim Plugins

It used to be that you would manually install a vim plugin for each of the various Go tools as well as using the the plugins that comes with Go itself.  Now, everything has been consolidated into a single Vim plugin, vim-go, and that's all you really need when it comes to Go-specific plugins.  A few other plug-ins such as Tagbar and YouCompleteMe are useful to complement your development environment, though.  I highly recommend that you use Vundle to manage your plugins.

vim-go

Vim-go brings together all the various plug-ins and feature for Go development in VIM including autocomplete, snippet support, improved syntax highlighting, go toolchain commands, etc. in a single package.

YouCompleteMe

YCM is a fast code completion engine for VIM that works as you type.  YCM requires VIM 7.3.584 or above and CMake (you'll need to compile the extension after it's downloaded).

Tagbar

A great way to view the tags in your code.  This requires that you have Exuberant Ctags and gotags installed.

Bufexplorer

My favorite plugin for navigating between VIM buffers.

.vimrc


" Go Specific Stuff
                                                             
au BufRead,BufNewFile *.go set filetype=go                                     
autocmd FileType go setlocal softtabstop=4
autocmd FileType go setlocal shiftwidth=4
autocmd FileType go setlocal tabstop=4

" go-def settings
let g:godef_split=2
let g:godef_same_file_in_same_window=1

" go-vim settings
let g:go_fmt_command = "goimports"
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1

" tagbar settings                                                                  
let g:tagbar_type_go = {
    \ 'ctagstype' : 'go',
    \ 'kinds'     : [
        \ 'p:package',
        \ 'i:imports:1',
        \ 'c:constants',
        \ 'v:variables',
        \ 't:types',
        \ 'n:interfaces',
        \ 'w:fields',
        \ 'e:embedded',
        \ 'm:methods',
        \ 'r:constructor',
        \ 'f:functions'
    \ ],
    \ 'sro' : '.',
    \ 'kind2scope' : {
        \ 't' : 'ctype',
        \ 'n' : 'ntype'
    \ },
    \ 'scope2kind' : {
        \ 'ctype' : 't',
        \ 'ntype' : 'n'
    \ },
    \ 'ctagsbin'  : 'gotags',
    \ 'ctagsargs' : '-sort -silent'
\ } 

Sunday, March 27, 2016

Upgraded to Fedora 23

Upgraded from Fedora 22 to 23 using the new dnf upgrade.  It was a pretty smooth upgrade almost like it was just upgrading packages.

Only issue I've noticed so far was that I wasn't able to access any of my other machines on the network using their .local name.

To fix this, I had to edit /etc/nsswitch.conf and change the hosts line to be:



hosts:      files mdns4_minimal [NOTFOUND=return] dns myhostname mymachines
Which was what was there previously but changed in the upgrade.  I might have accidentally brought it on myself by telling Fedora to replace my local changes with what is defined in the package.  Putting it back tells the system to try resolving using Avahli multi-cast name.

Once the change is saved, then restart the network manager:

sudo systemctl restart NetworkManager.service

Sunday, January 10, 2016

Tools of the Trade

Here is what I have in my professional toolkit. These are things that I always try to have on my system. Everything here is free with many them being open source. I originally published this list about 15 years ago and this year I finally revisited it and cleaned things up. What I discovered was that the open source projects are the ones that most likely survived the test of time.
See my posts on recommended books

Programming Languages

  • Go Programming Language - Open source programming language that makes it easy to build simple, reliable and efficient software (Quoted from the Go site but is pretty accurate). This is my favorite language as it blends the compile nature of C with the practical aspects of a scripting language.
    • Check this post on setting up Vim for Go.
  • GNU GCC - Open source C/C++ compiler supported on so many platforms now that I can’t list them on. There’s even ports of it so that you can compile games to run on the GBA. C is the foundation language of enabled the growth of our profession and is a must learn of every software engineering.
  • Perl - One of the great scripting languages although admittedly I rarely use it now. In many instances, Python has taken the mantel of Perl, but Go might replace both.
  • Scheme - I don’t really do much with Scheme, but I believe it’s worthwhile for engineers to have exposure to this form of programming.
  • Polymer Project - For web front-end development Javascript, for better or worst, is the defacto language of the browser, but if building anything beyond the most basic web site, you’ll probably need to use some kind of JavaScript library or framework. I like using the Polymer library since it embraces web components.

Programmer’s Editor

  • Vim - Although I started as an EMACs user, VIM is now my primary editor..
  • GNU EMACS - EMACS is more then an editor, it’s a way of life!
  • Notepad++ (Windows)

Web Browser

Databases

  • PostgreSQL - Top notch standards-compliant RDBMS
  • FreeToad - GUI client for accessing Oracle databases.

Multimedia

  • VideoLAN VLC - Open source media player that can play just about any format without the hassle of installing a bunch of codecs individually.
  • Handbrake - Allows conversion between different media formats.

Graphics

  • SketchUp - 3D modeling program. SketchUp Make is the free version. (not open source)
  • Blender - Open source 3D modler ala Maya.
  • IrfanView (Windows) Fast graphic view that’s small, fast, but loaded with features.
  • GIMP - Photoshop-like graphics program.
  • Inkscape - Vector graphics editor.

Source Control

Communications

  • Pidgin
  • Weechat
  • IRC

Operating Systems

Cloud

Windows/DOS