-4

I am planning to do some program analysis on Golang, just like pylint, trying to find issues from source code. So the first question I need to ask is:

What are the common pitfalls specialized in the Go language?

I know there are some ones in Python, e.g. array variables '[]' as parameters, and mutable vs immutable objects. (See more here and there).

Example 1:

>>> def spam(eggs=[]):
...     eggs.append("spam")
...     return eggs
...
>>> spam()
['spam']
>>> spam()
['spam', 'spam']
>>> spam()
['spam', 'spam', 'spam']
>>> spam()
['spam', 'spam', 'spam', 'spam']

Example 2:

Map<Person, String> map = ...
Person p = new Person();
map.put(p, "Hey, there!");

p.setName("Daniel");
map.get(p);       // => null

So what I really want to know is the similar ones in Golang. I have search the web but cannot find it. I also review some git repository history (e.g. docker.io) but cannot get typical ones. Could you kindly provide me some examples such as memory leaks, concurrency, unexpected results, and misunderstandings.

Community
  • 1
  • 1
Tao HE
  • 300
  • 1
  • 5
  • 2
    This is more of a poll and/or request-for-article. When you find a *particular* "pitfall" ask a focused question about it :) – user2864740 Jan 23 '14 at 01:10
  • http://golang.org/doc/effective_go.html – elithrar Jan 23 '14 at 01:48
  • First thing that comes to mind as a common mistake: not checking error return values. – Eve Freeman Jan 23 '14 at 02:52
  • 1
    @elithrar has already correctly pointed out the effective Go document. This *really* does cover most of the issues that people coming from other languages will encounter. Other than that, read some SO answers and see where most people are getting stuck. The main areas seem to be with trying to use OO idioms (inheritance etc.), not fully understanding the type system, and understanding idiomatic concurrency patterns using channels and goroutines (there are a few good presentations to be found regarding this last point. Do a Google search for "golang concurrency patterns".) – Intermernet Jan 23 '14 at 11:56

1 Answers1

4

Golint is a linter for Go source code.

peterSO
  • 158,998
  • 31
  • 281
  • 276