4 ms·
As usual, I think it depends on the situation. Certain parts of Java's verbosity are just a net loss. However, some of those pain points have been addressed, an
by wtetzner 6y ago
As usual, I think it depends on the situation. Certain parts of Java's verbosity are just a net loss. However, some of those pain points have been addressed, and they're working on addressing others.
For example:
public class Point {
private final x;
private final y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
I don't think this level of verbosity helps readability (at least not for anyone familiar with the language). Luckily, there's Lombok (and I think a recent or upcoming Java version is adding support for record syntax):
@lombok.Value
public class Point {
int x;
int y;
}
- martinp 6y agoRecords were introduced in Java 14 [1]. An immutable DTO, with minimal boilerplate, that still behaves a class. Example: record Point(int x, int y) {} [1] https://blogs.oracle.com/javamagazine/records-come-to-java https://blogs.oracle.com/javamagazine/records-come-to-java
- Twisol 6y agoThey were a preview feature until Java 16, though, so they probably haven't seen wide use yet. https://openjdk.java.net/jeps/395 https://openjdk.java.net/jeps/395 Java 16 was only released within the last few weeks! (Gradle still has some trouble compiling it or running on it; Gradle 7 should be dropping soon with explicit Java 16 support.)
- humbleMouse 6y agoTake a step up the enlightenment ladder and put a type dynamic language on top of java. Lombok is silly and makes your object’s serialization capabilities a dice roll. Keep annotations to a minimum and bring in a type dynamic language (groovy, kotlin, etc)
- AtlasBarfed 6y agoYes, groovy + @CompileStatic is comprehensively better than java with little to no performance loss.
- deleted 6y ago[deleted]
- humbleMouse 6y agoExactly.... all the benefits of dynamic, with all the benefits of static compilation.
- kaba0 6y agoI have no problem whatsoever with groovy, but I heard “all the parts Java programmers hate about JavaScript with all the part JavaScript developers hate about Java”, and I had to reread your reply to realize you are not writing something like this :D
- spicybright 6y agoI find static languages much easier for large code bases. Also, can you code dynamic features with java's reflection API? https://docs.oracle.com/javase/tutorial/reflect/index.html https://docs.oracle.com/javase/tutorial/reflect/index.html
- dunefox 6y agoKotlin is statically typed. It has full type inference, though (AFAIK).
- yawaramin 6y agoKotlin is statically typed. Perhaps you mean Clojure.
- dunefox 6y agoLike this? https://common-lisp.net/project/armedbear/ https://common-lisp.net/project/armedbear/
- mabbo 6y agoYou can go even further with Java 16, which came out last month. record Point(int x, int y) { } No lombok needed. That is the same code, but it also has equals and hashCode methods. https://openjdk.java.net/jeps/395 https://openjdk.java.net/jeps/395
- norswap 6y agoI don't think this is a good example, because it's easy to read in any case. The readability of the easy parts is not what matters - it's the readability of the hard parts, since that's where you'll spend 95+% of your attention.
- wtetzner 6y agoMy point is that adding that level of verbosity for something that should be simple makes it really hard to find the important parts of the code. Boilerplate obfuscates.
- jayd16 6y agoC# solves it well with auto Properties. Java records will be a nice addition.