Tools

GoLand’s Take on Go Development

Hello, My name is Andrey and I work at JetBrains. Even though in the last five years I have been heavily involved in product marketing and product management, I’m an engineer by heart and like to get my hands dirty from time to time. I’m always keen to learn new things and so about a year ago when Sergey and Alex, colleagues of mine, started working on the Go IDE, I decided to join their team part-time and help them where I could and learn Go development along the way. Two weeks ago GoLand went public as a new JetBrains IDE for Go. I’m very happy about this. For me and as well for the whole team, this is a very important milestone.

whole team, this is a very important milestone.

Gopher image courtesy of @tenntenn

Throughout the year I was asked about a thousand times why we’re working on GoLand and what’s so special about it when compared to the other IDEs and editors available on the market. Since GoLand is now out and I anticipate even more questions like this, I have decided to put all the points together in one post so I can refer to it in the future. For those of you that have similar questions and wonder if it’s worth taking a look at GoLand I hope that you also find this post useful.

Below I tried to summarize the major advantages of GoLand as a Go IDE as objectively as I could despite me being part of the GoLand team. I appreciate if you could share your own experiences in the comments. If you do, please try to be objective and constructive as well. If you use another tool and love it, I’d be happy to hear more about it. Tool choice is a subjective thing and there’s no right or wrong choice.

When making your decision on whether or not you want to try GoLand, use your own judgment and the feedback you hear from those who have tried it and compared it with the other options such as VS Code, Vim, etc.

Go!

Code completion

Well, completion is one of the fundamentals that you should have when you write code. On top of Basic Completion (which is similar to the completion you can find in other IDEs), GoLand offers so-called Smart Completion (Ctrl+Shift+Space for Windows/Linux and Cmd+Shift+Space for macOS) that will suggest only the expressions that are applicable to the code according to their type and the current context:

When declaring parameters of a function, the IDE may guess both the type and the parameter name. If you declare functions often, it may save you a lot of time in the long run:

Note, the IDE is able to guess if you type a name of a function or a type from a non-imported package and if you accept such a suggestion it will add the corresponding import on-the-fly. With GoLand at hand, writing import statements should be a thing of the past, since the IDE is able to adjust import statements on-the-fly based on accepted completion suggestions.

Code completion for the name of a function or field works even if the qualifier is not complete:

Any expression on the left side of the caret can be easily transformed to another one by adding a postfix to it after a dot and pressing Tab. The transformation is performed based on the predefined template, the current context, and the expression type:

The list of supported templates can be found in Settings | Editor | General | Postfix Completion:

Intention actions and quick-fixes

Since the IDE parses and deeply understands the code you’re looking at, it can not only notice certain issues but it can also transform the code and fix them for you. When your code references an undeclared function, you can ask the IDE to declare this function for using the correct signature made based on the context. To do that, use the corresponding intention action (Alt+Enter):

A similar quick-fix is available for unresolved fields. It declares the field for you and uses the type taken from the context:

If you’d like to add an alias for an import statement, you can rely on the corresponding intention action that will not only add the alias you need but will also replace all usages accordingly:

Writing the code that initializes a struct at the caret can be “automated” if you use the corresponding intention action (Alt+Enter):

When you need a struct at the caret to implement an interface, you can use either the dedicated Implement Interface action (Ctrl+I) or the corresponding intention action (Alt+Enter). In both cases, the process is very straightforward and only needs you to enter the name of the interface. Here just as anywhere else you can rely on code completion:

When the IDE spots a redeclared function, variable or constant in the same package, it not only shows you a warning but also offers you a quick-fix that navigates to the other duplicates:

If the IDE notices an import statement for a package that is not installed, you’ll see a warning and the available quick-fix to install the package:

Once the package is installed you can quickly navigate to the corresponding sources folder in the Project tool window by clicking it holding Ctrl for Windows/Linux and Cmd for macOS.

Refactorings

Refactorings is another fundamental need one may have when making changes to a program.

With GoLand, you can extract a function from an expression at the caret, or from a group of selected statements, by using the dedicated Extract action (Alt+Ctrl+M for Windows/Linux and Alt+Cmd+M for macOS), or selecting the Method option in the generic Refactor This popup (Ctrl+T):

The same refactoring is available for variables (Alt+Ctrl+V for Windows/Linux and Alt+Cmd+V for macOS) and constants (Alt+Ctrl+V for Windows/Linux and Alt+Cmd+V for macOS).

You can inline a constant, or variable at the caret by using the dedicated Extract action (Alt+Ctrl+M for Windows/Linux and Alt+Cmd+M for macOS), or select the Inline option in the generic Refactor This popup (Ctrl+T). The IDE will update all references to the symbol and replace them with the value:

Navigation

One thing that you do more often than write code is read code. GoLand helps here as well. For example, the IDE lets you instantly navigate to an interface implemented by the type at the caret with one click: either by clicking the icon on the left side of the editor, using the dedicated Show Interfaces (Ctrl+U for Windows/Linux and Cmd+U for macOS) action, or by using the corresponding intention action:

A similar icon, dedicated action (Show Implementations via Ctrl+B for Windows/Linux and Cmd+B for macOS) and intention action can navigate you to types that implement the interface at the caret.

Every time you see a popup with a list of symbols, be it usages, implementations, implemented interfaces or completion suggestions, you can call Quick Definition (Ctrl+Shift+I for Windows/Linux or Cmd+Y for macOS) or Quick Documentation (Ctrl+Q for Windows/Linux and Ctrl+J for macOS) to have another popup open aside it with the definition or documentation for the selected symbol:

If you ask the IDE to find you all usages of a function that implements an interface, the IDE will prompt you to also look for usages of the corresponding interface’s function:

Misc

To make the code more readable, the editor shows so-called Parameter Hints for literals and nils used as method arguments or named return values:

To take it even further, every parameter and local variable can be highlighted with its own color:

If your Go code has C fragments, the IDE will automatically provide syntax highlighting, basic validation, and completion:

For those of you who use database/sql, jmoiron-sqlx or markbates/pop in your code, you may notice that the IDE offers syntax highlighting, basic code completion, and validation of SQL statements:

The coding assistance is aligned with the selected dialect and the configured data source if any.

Running applications and tests takes no configuration and can be done with one click:

For tests, the IDE will prompt you to not only to run or debug it but also run with coverage. If you use the latter, the IDE will collect the coverage data and show it in both the editor and in the dedicated tool windows in the aggregated form.

Finally, GoLand provides 100% of the WebStorm functionality: JavaScript, TypeScript, React, Angular, aetc.

Drawbacks

By now you probably thinking that this is all some kind of trick. It would be too good to be true if there were no downsides in addition to all those benefits I was talking about above. You’re right, but the trick, in my opinion, is very simple. GoLand has two major downsides.

First, GoLand is a commercial IDE. You have to buy a license if you want to use it longer than 30 days. That is unless you’re an open-source contributor or a student. In these cases it’s free.

If you purchase the IDE as an individual developer, then it’s about half the cost of purchasing it as a company. If you purchased an IDE once, you can use the version that was available the moment you purchased it, forever, and you get bugfix updates. If you want to get major updates every four months, you have to renew the subscription every year. On a positive side, if you renew your subscription, the price is 20% cheaper each time up to 40% off after 3 years.

Second, before you can use all those coding assistance features I was mentioning above, the IDE has to index your project files along with the configured GOPATH and vendor directory. Normally this is a one time operation and it may take from several seconds up to several minutes depending on your GOPATH directory size, the installed plugins and the type of your disk (with SSD it’s a way faster; with NFS it’s rather slow). To reduce the indexing time per project, you can configure separate GOPATH directories for each of your projects.

If you’re used to Vim or Emacs of course the learning curve might be quite steep. Vim users may find it helpful to install and use ideaVim plugin.

Conclusion

If you made it here, you might have a better understanding of whether GoLand’s benefits outweigh its downsides. Realistically you can only answer this if you try them yourself.

If you decide to try GoLand, you can download it on its official website here and try it out for 30 days before you have to buy a license (or ask your company to buy it for you).

A few more useful links:

Thanks to David Watson and Florin Patan for reading the draft of this post.

Andrey Cheptsov