| I'm learning Go right now by writing a small part of my current project in it. I like it quite a lot (mostly for its concurrency features) but it is actually a surprisingly verbose language compared to Java. First of all you have this on about every second line: if err != nil {
return err
}
Method signatures are convoluted because you have to repeat the receiver type for every single method and add (actualReturnType, error) at the end.Go: func (MyType* mt) myMethod(s string, i int) (string, error)
Java: String myMethod(String s, int i)
For functions you want to use in expressions you need a second one that calls the first one and panics instead of returning err.You can't specify default values for structs, so you often need an extra function that constructs a default instance of the struct and initializes its fields. And the lack of generics means you have to write a lot of things several times for different types. Lambdas are very verbose as well. You get no type inference even in contexts where it would be simple to do: Go: filter(func(s string, n int) { return len(s) < n })
Java 8 (Scala is similar): filter((s, n) -> s.length < n)
Function names often have to be longer because there is no function overloading.Go's simplicity is a double edged sword. Lack of verbosity is definitely not its strength. Obviously there are many counter examples where Java is more verbose than Go. But they are very well known by now so I'm not going to repeat them here. |