DEV Community

Saami abbas Khan
Saami abbas Khan

Posted on

Are We Sacrificing Readability for Conciseness in Modern Java?

Hey everyone!

I’ve been working with Java’s lambda expressions lately, and something has been bothering me: are we sacrificing readability for the sake of conciseness?

I often see developers cramming everything into a single line, especially when using lambdas, streams, and method references. Sure, it looks clean and concise, but sometimes it’s just too hard to immediately figure out what the code is doing. For example:

names.stream()
    .filter(name -> name.length() > 3)
    .map(name -> new StringBuilder(name).reverse().toString().toUpperCase())
    .distinct()
    .sorted((a, b) -> b.compareTo(a))
    .forEach(name -> System.out.println("Processed: " + name));


Enter fullscreen mode Exit fullscreen mode

I'd love to hear your thoughts!

Top comments (1)

Collapse
 
prsaya profile image
Prasad Saya

Yes, it is readable, clean, concise, expressive and also explains what it does clearly. I think you should use lambda expressions (and method reference expressions), when possible. Most of the commonly used Java APIs (file IO, collections, etc.,) now have APIs to use lambdas.

This also means using functional programming. Now you have object-oriented and functional programming capabilities to apply in your application development.