DEV Community


Discussion on: Why not Java

siy profile image
Sergiy Yevtushenko

Well, many "issues" are not issues but plain lack of knowledge. "Issues" listed as "language weakness":

  1. There is a comprehensive time-date-calendar framework in JDK. It's part of standard library for many years. Once it was added, I never had any task which involved time or date manipulation which would require any external libraries.
  2. You're mixing up two different things: Iterable and Stream. From the language standpoint Java arrays are Iterables, since you can use them in enhanced for loop (like for (Type value: iterable) {} ). And you can convert array into Stream using And, well, Java is not a Microsoft thing, there is no point to expect that something will have performance impact just because it's not a part of standard library.
  3. Every lambda type in Java corresponds to interface with single abstract method. This is the single, unified standard way to define lambda types. Functional interfaces already defined in standard library are for your convenience, but if you don't like them or don't want to search them, nothing prevents you to create your own. No point to complain and no "issue", just lack of knowledge.
  4. Must admit that I'm happy that Java has no async/await as part of language. There are two significant reasons for that:
    • These keywords is a huge reverence to imperative style. They result to non-composable, hard to read and maintain code. In contrast, Promises/Futures enforce functional, composable code style and don't need language level support.
    • Presence of such keywords would mean that this feature is locked to single implementation which not necessarily is the best one or completely fits my needs.

Remaining "issues" are of the same quality.

Thread Thread
davidsackstein profile image
david-sackstein Author
  1. There are more than one frameworks for describing time in Java and that is in itself a problem. I have not found one that provides the minimum I need easily. For instance, how do you construct a Date from its components, and how do you decompose it again. You need to start creating CALENDAR instances and so on. Of course it can be done, but it is verbose and messy. But even if I find the one and best, it is not easily compatible with the others. When you need to call other libraries that take Instant and you have Date or the library uses LocalDateTime and you have Calendar. Managing these conversions and the intricacies of each object are time consuming and shouldn't be.
  2. I am not an expert, but I am pretty familiar with Streams by now. I recommend you take a look at IEnumerable in .Net. with LINQ. I think you will agree that Streams are a very poor imitation of what can be done in a modern language. LINQ provides a functional language over all IEnumerables in a more succint and unified way. Streams are bogged down by the fact there is no support for extension methods in Java and that there is no one interface to describe all collections. Even creating a Stream is a big deal. To create a stream from an array you have to explicitly call Collecting streams is a big hastle often requiring combinations of static Collectors methods instead of a simple toArray or toList.
  3. Lambdas in Java are second class citizens. They are just replacements for interfaces. In order to use them you have to use a predefined interface type that matches your lambda signature. The most common ones exists, but you often need different ones (e.g. a lambda that takes 3 parameters, returns one and does not throw exceptions), and even if you have one that matches, you are forced to call its particular method (apply, supply or what not) which may not be intuitive in the context you are using it. In other languages, a lambda is a callable type and you call it with () just like a method.
  4. Async/Await is extremely powerful and is missing in the language. The poor support for this kind of concurrency in the language has lead to a plethora of Future libraries springing up to try to fill the gap. There is no disadvantage at all in locking you into a single implementation if that implementation is done well by the language developers. Implementing async await behavior is extremely difficult and I dont think you should be wishing you had the freedom to write it yourself. You might not do such a good job. (Maybe you will, but most people wont) ------ Since writing this post I have got to know Kotlin quite well and I can say that it does provide solutions for many of these issues over the JVM. The fact that JetBrains saw the necessity to implement lambdas as other modern languages do, to add the concept of sequence and to add extension methods is testimony that the many of the weaknesses that I have outlined in my post are indeed great drawbacks in the Java language that needed to be addressed. Unfortunately Kotlin still suffers from the terribly complicated dependency management issues that it inherits from the Java ecosystem, but as a language it is a great improvement.
Thread Thread
siy profile image
Sergiy Yevtushenko
  1. Date class is an old-fashioned way to work with date and time. There is a new java.time framework designed after Joda Time, one of the best tools dedicated to this topic.
  2. Java is not .Net and don't have to be.
  3. Lambdas in Java are replacement for anonymous classes. And like classes lambdas are first class citizens. If you need lambda with 3 parameters - create appropriate interface. What's the problem?
  4. As I told you, they harmful. And lack of them can't lead to any library since this is language level feature. As of asynchronous support, Java has CompletableFuture in standard library. This is, perhaps poorly named, but otherwise exceptionally good Promise implementation. So, there is no gap to fill. Nevertheless I'm happy that there is such a freedom since I wrote a replacement for CompletableFuture (and underlying scheduler). One of the reasons - my implementation uses Linux io_uring asynchronous I/O API which is only about a year old. Why should I wait for language developers if I can do that by myself?

As for Kotlin: it has couple of interesting ideas accompanied with pile of poorly thought out code size reduction hacks. Overall mix results to significant mental overhead which negativity impacts productivity, despite claims. By the way, it doesn't solve any real Java issues which Java unable to solve by itself. On the other hand, it might fit better to your expectations as it provides many useful tools to create mess in codebase, freedom to put any class in any file and extension methods are among them.