A lot of Golang is like this: very simple, almost trivial-seeming decisions that potently improve the language in practice. It's a fundamentally simple weapon, it's forged from Damascus steel.
if rt, ok := dst.(ReaderFrom); ok {
return rt.ReadFrom(src)
}
Isn't the most terrible way anyone has seen pattern matching implemented.At least it is better than Java's instanceof + cast.
switch i.(type) {
case OptionalInterface1:
// do some extra thing we allow
case OptionalInterface2:
// do some other extra thing we allow
}
It's really good when you have a set of mutually exclusive interfaces or types.Except that in a language with generics you have to cast far less, so it is no surprise that Java is less optimized for type casting.
(The primary exception being the equals(Object) method, which most classes should have.)
More importantly, it's a massively biased comparison to look at a language from 3 years ago and compare it to those from 20, 30 or 40 years ago. Of course the standard library will be cruftier in an older language. The Idris standard library is beautiful, really state of the art - as you'd expect from a language that's only been written in the last couple of years.
It will be interesting to see what the Go standard library looks like in 20 years' time; I'm betting it will fare less well than Java's, because the workarounds and cruft necessary to avoid breaking changes will be worse in a language without Java's type system. In the meantime, the fair and informative comparison to make is with languages of a similar vintage.
Really? Java's success is - rightly - attributed to its simple and usable libraries.
> To write clean Java you really need to avoid much of the standard library (read Effective Java by Josh Bloch)
Lol, the standard ArrayList.java is written by ... Josh Bloch!
There are many parts of the Java library to avoid. Some are obsolete and terrible, like CORBA or java serialization. Others are gotchas w weird semantics, like Object.clone(). Others are just bad API design--eg the built in IO libs don't require a Charset argument. The default is the "system default charset", which is apparently still the obsolete MacRoman if you're on OSX.
The most annoying are those shortcomings of the std library that cause extra complexity. For example, the built-in JUL logging framework sucks enough that almost everyone uses log4j or logback instead. But now you have user libraries using incompatible logging frameworks. Enter slf4j, a shim that ties them all together.
In my experiemce, Go is a breath of fresh air.
https://docs.oracle.com/javase/7/docs/api/java/security/Mess...
And here:
https://docs.oracle.com/javase/7/docs/technotes/guides/secur...
I think you can really judge a language accurately by checking out its standard library. This is one of my favorite things about Go.
By comparison,
* The C++ STL. Fast and useful, but the implementation is nearly unreadable due to template soup. Here's one of the simpler parts! https://www.sgi.com/tech/stl/stl_vector.h
* PHP. So bad it's basically a strawman. I'll include it because it's hilarious: http://www.forbes.com/sites/quora/2012/08/31/what-are-the-mo...
* Java. A bit better. Compare the readability of OpenJDK's ArrayList.java to the STL vector.h, which does essentially the same thing: http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/00cd9dc3c2b5/s...
But of course the Java standard library is immense and has a lot of cruft in it. To write clean Java you really need to avoid much of the standard library (read Effective Java by Josh Bloch) and add a few important missing parts (use Guava).
Golang is really unique in that regard. You can learn Go by reading the standard library. It is beautiful, linear code. The library is pretty complete--eg you can write a one-line HTTP file server out of the box--but nothing feels extraneous. Lastly, I think it gets close to Knuth's ideal of Literate Programming. Paragraph-length comments thoughout the standard library explain what's happening, how, and why.
For example, the post talks about how io.Copy is awesome. For a concise English explanation, why not go directly to the source!
https://golang.org/src/pkg/io/io.go#L329