5 ms·
Java is quite a bit more verbose than some other languages, but I think the culture is a significant factor; C# is similar. I've noticed the tendency to overabs
by userbinator 11y ago
Java is quite a bit more verbose than some other languages, but I think the culture is a significant factor; C# is similar. I've noticed the tendency to overabstract and overgeneralise, apply design patterns for the sake of using them, etc. is particularly strong. It's inexplicably hard to trace out the train of thought that makes things like this appear:
https://news.ycombinator.com/item?id=4549544 https://news.ycombinator.com/item?id=4549544
I've written small Java apps --- one class only, i.e. one source file --- which needn't be any more complex, yet coworkers have said there's something uncomfortable about my code; but for some reason can't explain exactly why. I'd get comments like "wouldn't it be better if you made this (only used once and very trivial) line of code a separate function?" "could you use more classes?" (for a <100LoC script-ish thing that had almost no duplicated code nor much in the way of loops.) It's almost as if they can't get their heads around how simple something can be, so it somehow feels very wrong to them.
Then there's the extremist "premature optimisation is evil" attitude, which I think is completely misguided because more code and complexity is bad not only in terms of computer time but also programmer time --- it takes more time for programmers to design, write, read, and debug more complex code.
- delecti 11y agoI've gotten many code review comments to the effect of "can you break this out into an interface?" so I 100% understand what you're saying. Many of the instances were things that we were only likely to make one example of either. I could see that argument being valid if there was a clear second implementation in mind, but an interface with only one implementing class is often just wasted time.
- rms_returns 11y agoThe verbosity in Java is soon going to be reduced by an extensive degree by the three new features included in `Java 8`, namely: 1. Lambdas: Lambdas are brief and to the point, the expressions reflect the terseness of `C/C++`. In many situations, you can totally do away with interface creation by just using a lambda instead. Consider all the lines of code saved in a legacy code by just using lambdas in code! 2. Default methods: Again, `Interface patching` is a curse that a lot of Java projects suffer from. Requirements change slightly and what your typical enterprise Java dev does is add patches upon patches and layers upon layers in an interface. With default methods, you can just add default methods to your existing interfaces without affecting the ABI of your app. Again, tons of redundant code saved here. 3. Type annotations: Again, your typical Java devs have to resort to ugly hacks to place any constraints on the object properties. With type annotations, all you have to do is: @NonNull String str; And lo and behold! The variable `str` cannot be assigned any `null` value. So, lots of validation code being saved here again. To the best of my knowledge, none of the above features exist in the `C#` language (yet), so I take it as a Java's edge over C#.
- danielvf 11y agoLambdas are use all over in idiomatic C#.
- paulddraper 11y agoIf by "soon" you mean a year and a half ago, then yes, soon :)
- rms_returns 11y agoI don't know what major project you are talking which uses these features. I'm not talking about small projects by John Joes, I'm talking about LARGE infrastructure projects. For example, Android SDK is extensively used in Java world, and the Android SDK has tons of Interfaces as either arguments or class helpers which can be substantially overhauled by using these features.
- SideburnsOfDoom 11y ago
- quanticle 11y agoI'd get comments like "wouldn't it be better if you made this (only used once and very trivial) line of code a separate function?" "could you use more classes?" The trouble is that there is a cargo-cult belief in unit testing in the Java (and .Net) worlds. Everything must have a full suite of unit tests, even if it's a one-off script. Therefore, in order to enable the mock objects needed for unit testing, you can't have "just" a class. You have to have an interface, which that class then implements. If you have any non-trivial piece of functionality, it must be encapsulated into its own method, otherwise, how are you going to test it in isolation. My belief is that it all stems from the fact that Java doesn't have a REPL, so programmers use "test-driven development" to get the same level of interactivity from their code.
- rtpg 11y agoa bigger culprit is a lack of first-class functions. Objects in Java basically exist to be structs and to hold onto methods.
- Chris2048 11y agoIn my early days - I once found a Tuple library for Java, and added it to the codebase. Senior devs soon instructed me to remove it - Back to a multitude of container objects...
- gravypod 11y agoWouldn't using a tuple in Java be like using inserting things into a Object[] and pulling them back out casting to the object you want to use? What library was this?
- Chris2048 11y agohttp://www.javatuples.org/ http://www.javatuples.org/
- V-2 11y agoHard to say without knowing more context, but they could have been right. Personally I'd prefer clearly named, domain-specific container objects with adequately named properties than having to deal with "anonymous" Tuples all over the codebase, and being forced to remember what the first element was, what the second one was etc.