Things I Hate - Go Edition
Cyclical dependencies
Go disallows circular dependencies between packages.
In Java this is allowed:
package b;
import a.A;
public class B {
public static void main(String[] args) {
System.out.println("A.main");
A.doA();
}
public static void doB() {
System.out.println("B.doB");
}
}
---
package a;
import b.B;
public class A {
public static void main(String[] args) {
System.out.println("A.main");
B.doB();
}
public static void doA() {
System.out.println("A.doA");
}
}
Similar code is forbidden in Go. If you want to have test utilities, you often run into circular dependencies, leading
to practices like https://golang.org/src/net/http/main_test.go, where a file packaged as foo_test
lives in the same
directory as files named foo
.
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package http_test
import (
"fmt"
"io/ioutil"
...
What an ugly hack.