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.

Popular Pragmatic Bookshelf topics Top

johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
New
telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
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
lirux
Hi Jamis, I think there’s an issue with a test on chapter 6. I own the ebook, version P1.0 Feb. 2019. This test doesn’t pass for me: ...
New
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New
brunogirin
When I run the coverage example to report on missing lines, I get: pytest --cov=cards --report=term-missing ch7 ERROR: usage: pytest [op...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
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
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
PragmaticBookshelf
A Hero’s Journey with Chris Pine @chrispine Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1132 25321 748
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New

Latest in Functional Programming in Java, Second Edition

Functional Programming in Java, Second Edition Portal