3 ms·
It is a useful convention in C and C++ to group includes, but I don't see the benefit in Go. Since gofmt sorts imports, the grouping is soon undone. In any c
by gyepi 13y ago
It is a useful convention in C and C++ to group includes, but I don't see the benefit in Go.
Since gofmt sorts imports, the grouping is soon undone.
In any case, it is quite easy to distinguish the three kinds of imports if local imports share a common prefix or set of prefixes.
Am I missing something here?
- agentS 13y agoNote that gofmt sorts within groups. So if you leave spaces between groups of imports, it'll sort them all separately. Presumably, this sort of grouping is the reason it does it this way.
- codebeaker 13y agoIt's possible that if you have packages that understand flags (config package, with flags in init(), for example) that if you include it after the testing package, or before. One of them won't accept flags. (because flag.Parse() has already been called)
- 1631- 13y agoYou can't rely on the order of imports initialization anyway. See http://golang.org/ref/spec#Program_execution http://golang.org/ref/spec#Program_execution .. I believe that's also the reason, you shouldn't call `flag.Parse()` in `init()`
- deleted 13y ago[deleted]