dtonhofer

dtonhofer

Functional Programming in Java, Second Edition: Chapter 12 "Functional Programming Idioms", some notes

On page 179:

First, imperative style was the way of life in Java and most programmers are very familiar with that style, since that was the only option for a long time.

In other words: Java is a member of the family of ALGOL-style languages derived from ALGOL 60.

A subchapter that is missing may be;

Use Records

Functional languages allow creation of data structures “on the fly” (e.g. the LISP cons or the Clojure “map” construct), the near-equivalent seems to be the record. It is very useful in stream pipelines to create new forms of data to be passed rightwards. It’s definitely more informative than using general maps for this task.

However, records should probably not be used outside of a local context or even in an API, use proper classes for that.

In

Use Type Inference for Parameters

one might mention that using var for field declarations is a good thing and not shameful, unless it is better to write the whole type for clarity for the other members of the team. (but the IDE will inline a note on the type anyway)

A special note on

Datastructures

which for functional programming are either primitive and immutable or complex and “pretend immutable” by not allowing any modifications, only allowing 1) copying 2) creating a modified copy (which is done efficiently “under the hood”) Only dropping references to whole or parts of these structures will allow reduction in size via eventual garbage collection.

For example, in Clojure: Clojure - Data Structures

However, Java collections for example are not like that at all, at best we can make them immutable by wrapping with an “unmodifiable” decorator. What is to be done? Are there libraries that have tree structures (say) that efficiently implement “immutability” semantics.

Where Next?

Popular Pragmatic Bookshelf topics Top

jdufour
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
New
raul
Hi Travis! Thank you for the cool book! :slight_smile: I made a list of issues and thought I could post them chapter by chapter. I’m rev...
New
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
jeremyhuiskamp
Title: Web Development with Clojure, Third Edition, vB17.0 (p9) The create table guestbook syntax suggested doesn’t seem to be accepted ...
New
New
jgchristopher
“The ProductLive.Index template calls a helper function, live_component/3, that in turn calls on the modal component. ” Excerpt From: Br...
New
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
New
s2k
Hi all, currently I wonder how the Tailwind colours work (or don’t work). For example, in app/views/layouts/application.html.erb I have...
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New

Other popular topics Top

wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
AstonJ
Or looking forward to? :nerd_face:
New
AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New
AstonJ
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New
Fl4m3Ph03n1x
Background Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
New

Latest in Functional Programming in Java, Second Edition

Functional Programming in Java, Second Edition Portal

Sub Categories: