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

jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
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
conradwt
First, the code resources: Page 237: rumbl_umbrella/apps/rumbl/mix.exs Note: That this file is missing. Page 238: rumbl_umbrella/app...
New
cro
I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
kolossal
Hi, I need some help, I’m new to rust and was learning through your book. but I got stuck at the last stage of distribution. Whenever I t...
New
ggerico
I got this error when executing the plot files on macOS Ventura 13.0.1 with Python 3.10.8 and matplotlib 3.6.1: programming_ML/code/03_...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New
dachristenson
@mfazio23 Android Studio will not accept anything I do when trying to use the Transformations class, as described on pp. 140-141. Googl...
New

Other popular topics Top

Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1142 25765 758
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
New
DevotionGeo
I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New

Latest in Functional Programming in Java, Second Edition

Functional Programming in Java, Second Edition Portal

Sub Categories: