• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Grokking Functional Programming - general approach question

 
Greenhorn
Posts: 10
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michał Płachta, everyone.
Great to see another Grokking series book.
In the book introduction, you wrote "functional programming and writing maintainable software". As probably many of us, I've seen some unmaintable lambdas in my life. Code so convoluted, that it could be considered an entry for Obfuscated Code Contest.
What measures can be taken to enforce functional programming bits written in a readable way, promoting conciseness while still benefittng from the new paradigm?
It also seems that many enter this brave new world, but not everyone stay. Especially in java, some early adopters tend to write as much lambdas as they can, but later they withdraw and try to find balance. Repositories around the world could tell a lot about this kind of evolution. What course should be taken here for junior developers - should they be encourage to write as much FP as possible?
Do you have any hints that tackle this?
 
Author
Posts: 31
5
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great question. I have seen bad OOP codebases and I have seen bad FP codebases. If these two facts prove anything, it's that the paradigm we choose doesn't guarantee anything. ;)

Grokking FP is discussing creating maintainable codebases using FP techniques that are universally accepted. These techniques are not specific to any programming language. They are coming to many mainstream languages as well. That approach alone avoids introducing a lot of shiny things that are functional, but also scary to many developers coming into FP.

In the book, you see a big focus on immutability. You don't see any push toward generalization or high-level abstractions... The mindset of transforming immutable values using pure functions is so powerful that it's enough to implement a lot of non-trivial applications. We could, of course, write these applications using different, more advanced FP techniques but the cost is pretty big: newcomers struggle, the team can't grow, and the product becomes unmaintainable. So we try to learn to write simple FP code.

Regarding your point about Java early adopters: the objective of writing Java "functionally" is not to write as many lambdas as possible. Even in the book, I show Java examples that are FP and don't use lambdas. A static method that takes an immutable value returns an immutable value and doesn't do any side effects is functional.

Finally, the objective of writing "functionally" is not to write functions for the sake of functions. We want to write code that is easy to read, easy to maintain and hard to break. And it looks like many FP techniques help o achieve that.
 
Andrzej Maslowski
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply, Michał.
I guess I don't have enough FP experience to go beyond lambdas yet. Your response tells me a lot about what I don't know:)
As it seems you really know your trade, I'm really looking forward to reading the book and expand my toolset.
 
Sheriff
Posts: 17715
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michał Płachta wrote:Finally, the objective of writing "functionally" is not to write functions for the sake of functions. We want to write code that is easy to read, easy to maintain and hard to break.


This alone is reason enough to get the book.
 
Do not set lab on fire. Or this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic