6 ms·
I mean that you will need to write more, and more duplicate code, to express the same, it’ll be less clear, and less safe. Generics, and annotation processing
by kuschku 10y ago
I mean that you will need to write more, and more duplicate code, to express the same, it’ll be less clear, and less safe.
Generics, and annotation processing with code generation integrated in the compiler, are two example features supported by Java that improve this.
Haskell obviously is a lot better even.
Additionally, it’s also a question if, in the language, any state of the program is immediately obvious from the code – or if the syntax hides things (such as Go’s multi-return errors vs. Java’s exceptions, although Java could use an "ignore" keyword to ignore any error happening in a block or statement)
A powerful static type system can express everything a dynamic type system can, and more. (That’s why I tend to err towards static typing)
- amelius 10y ago> Generics, and annotation processing with code generation integrated in the compiler, are two example features supported by Java that improve this. I think it is fair to point out that generics were not part of the first Java spec. They were added in version 5, see [1]. [1] https://en.wikipedia.org/wiki/Generics_in_Java https://en.wikipedia.org/wiki/Generics_in_Java
- kuschku 10y agoOf course not. Early Java was comparable to today’s Go in many ways, and Generics is part of that.
- cube2222 10y agoVery little people who have tried errors by value or Either monads (they are basically the same concept in some sense) think that exceptions are better. Exceptions cause your code to be non-linear. Also, it makes them seem like something exceptional (pun intended), whereas you should really carefully handle each error and decide what it implies. Also, just something I noticed after almost two years of Go. Thanks to library quality I usually end up writing much less Go than Java/Scala for similar applications.
- kuschku 10y agoGo does not have Either monads, or real errors by value. It has a multi-assignment syntax similar to tuple return, but nothing else. For Java, with a tiny library, you can have real Either monads: https://github.com/spencerwi/Either.java https://github.com/spencerwi/Either.java I use them in lots of code. For Go, you end up with an assignment syntax where you have to manually check, and get no compiler safety. At all.
- cube2222 10y agoYou do have errors by value. You return for example two values, the response and error. What do you mean with no compiler safety exactly?
- kuschku 10y agoI mean that the compiler does not check if I’m handling the error. I can easily just ignore the error and work with the value, and therefore have code that breaks if the value might not be there. Any code that compiles should not be able to ever segfault or have NullPointerExceptions or similar.
- cube2222 10y agoWell, I never had segfaults. Anyways, it's true, I miss pattern matching on errors. However, in practice, you just get used to it. I haven't had a situation in the past half year where I'd forget to handle the error / check it.
- kuschku 10y ago> However, in practice, you just get used to it. I haven't had a situation in the past half year where I'd forget to handle the error / check it. But with the same argument, you could as well use PHP7. And this still doesn’t allow you to replace all stdlib datatypes with your own implementations without using custom precompilers.