paint-brush
Go gotchasby@vamsee
417 reads
417 reads

Go gotchas

by Vamsee KanakalaApril 18th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Go language is being developed by <a href="https://hackernoon.com/tagged/google" target="_blank">Google</a> and it is becoming popular fast. It also has it’s own share of shortcomings that might be frustrating to developers who are familiar with other much more expressive languages.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Go gotchas
Vamsee Kanakala HackerNoon profile picture

Go language is being developed by Google and it is becoming popular fast. It also has it’s own share of shortcomings that might be frustrating to developers who are familiar with other much more expressive languages.

Advantages

  1. Killer feature of Golang is channels and goroutines. This feature makes it dead simple to write concurrent code.
  2. Producing single executable binary which you can deploy directly on server without any other external dependencies.
  3. Type system is simple and straight forward and works most of the time.
  4. Faster compilation times. Good for developer productivity.
  5. Excellent testing, documentation support.
  6. CLI development tools that complement editors like vim to make development breeze.

Now the gotchas

Dependency management

Dependency management is subpar. Recently there were efforts to flesh out some kind of vendor management. But it is in the works and at alpha stage. Go needs something like npm/yarn or bundler. There are third party tools like glide which pick up the task where Go developers dropped the ball. It’s not realistic to expect a language to become popular in the long term just on the basis of brand value.

Generics

This is one of the pain point of Go language. Go has generic like support for doing common tasks such as sorting but for anything other than typical sort you have to write separate version of code for each type that you want to use. You can use tricks like empty interfaces to simulate generics but it’s not optimal.

The reason given by Go developers for not adding generics is that it will have considerable impact on compilation time and add complexity to the language. It might be true but the issue is taking political color. Nobody wants to see anti/pro template anarchist groups. :)

Error handling

You basically check if the error returned by a function is nil or not. If it is not nil then you either panic or handle it the correct way. Looks simple and in fact it is simple to write. But it is very verbose and it will suck the soul out of people who write and read Go code particularly on large codebases.

Go should have something like option type which exists in languages like Haskell and Rust. For example most functions in Rust standard library return option values which could be either None (null) or Some (Value) and offers convenient unwrap function which panics on null values. It is concise when you just want to terminate program on null value. Compiler also enforces null checking when doing things like pattern matching. It’s difficult to implement something like this without some form of template support in Go language.

Conclusion

Now a days there are so many languages in the development that offer rich features much better than Go language. Go language is the modern day Java which any one can pickup and particularly companies will have easier time writing/maintaining Go code. For any one who might like things little different Go might look like a hammer. Personally I like languages that are in dead middle of Go simplicity and Haskell expressiveness. Finally Go developers should look at usage patterns of their language outside of their company. It’s little ridiculous to expect developers to import a third party library directly from a url.

Hacker Noon is how hackers start their afternoons. We’re a part of the @AMIfamily. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.

To learn more, read our about page, like/message us on Facebook, or simply, tweet/DM @HackerNoon.

If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!