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

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
Razor54672
The answer to 3rd Problem of Chapter 5 (Making Choices) of “Practical Programming, Third Edition” seems incorrect in the given answer ke...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=> (create-migration "guestbook") Execution error (Ill...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
raul
Page 28: It implements io.ReaderAt on the store type. Sorry if it’s a dumb question but was the io.ReaderAt supposed to be io.ReadAt? ...
New
swlaschin
The book has the same “Problem space/Solution space” diagram on page 18 as is on page 17. The correct Problem/Solution space diagrams ar...
New
dsmith42
Hey there, I’m enjoying this book and have learned a few things alredayd. However, in Chapter 4 I believe we are meant to see the “>...
New
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
New
dachristenson
I’ve got to the end of Ch. 11, and the app runs, with all tabs displaying what they should – at first. After switching around between St...
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
DevotionGeo
I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New
axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
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
AstonJ
Biggest jackpot ever apparently! :upside_down_face: I don’t (usually) gamble/play the lottery, but working on a program to predict the...
New
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New

Latest in Functional Programming in Java, Second Edition

Functional Programming in Java, Second Edition Portal

Sub Categories: