• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Effective Java: Functional programming features in Java roadmap

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mr. Bloch.

Glad to have opportunity to ask you a question:

Do you think that Java should include in future releases more functional programming features like Scala language has?

Thanks for your answer!
 
Author and "Sun God"
Posts: 185
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Camilo! I do think that Java should continue mining functional programming for good ideas, but I don't think Java should adopt all the FP constructs present in Scala. If people want to program in Scala, they can! Java is simpler than Scala, and more of a "blue collar language." That's the soul of Java. Of course it's been moving further from that ideal at least since generics (especially wildcards) were added in Java 5. It's a tough balancing act. You want to provide useful facilities, but at the same time a language only has space for a certain amount of complexity until it becomes unwieldy. Java is already becoming unwieldy. So my answer is, yes Java should consider more functional programming features, but it should only include them if they're really compelling, and easily understandable to Java's target audience.

It isn't always clear what's too complex. As an illustrative example (from Item 45), it's unclear which of these two methods of computing the Cartesian product is superior:



Here's what I say in Item 45:

Which of the two versions of newDeck is better? It boils down to personal preference and the environment in which you’re programming. The first version is simpler and perhaps feels more natural. A larger fraction of Java programmers will be able to understand and maintain it, but some programmers will feel more comfortable with the second (stream-based) version. It’s a bit more concise and not too difficult to understand if you’re reasonably well-versed in streams and functional programming. If you’re not sure which version you prefer, the iterative version is probably the safer choice. If you prefer the stream version and you believe that other programmers who will work with the code will share your preference, then you should use it.



I have mixed feelings about "pattern matching" (not the regex kind), which I know is being discussed for a subsequent release. Done well, it is powerful and concise, but it undeniable that it adds to the conceptual weight of the language.


    Bookmark Topic Watch Topic
  • New Topic