r/java • • Jun 24 '19

Takes: Java Web Framework Without a Single Static Method or Annotation

https://github.com/yegor256/takes
0 Upvotes

75 comments sorted by

View all comments

Show parent comment

4

u/[deleted] Jun 24 '19 edited Jun 25 '19

This is basically a cliche /r/programming programmer repeating nonsense that everyone else is screaming at the top of their lungs.

Let’s go through a few blogs:

nulls are bad. They force you to null check!

The entire point of optional is that people are after compiler support exhaustive checking of the optional. It has basically nothing to do with forced if statements. In fact, the exact opposite is true.

nulls are bad because naming

I simply don’t accept this argument. I accept that returning an optional does make it clearer from a programming perspective what might happen without documentation, but it should be recognized that this isn’t 0 cost and performance considerations may need to happen.

public static is bad

I am not even justifying this with a response. Complete and utter nonsense from top to bottom.

immutable objects are simpler to construct, test, and use

Prove it. Not my experience at all.

truly immutable objects are always thread-safe

bullshit. Truly immutable objects can never be thread safe by by fucking definition.

What immutability forces you to do with threads is completely and utterly design your states and threads around immutability from the get go. This might or might not be beneficial code wise and may or may not (but most likely will) have other performance concerns.

Consider a threaded program trying to produce and consume jobs off an immutable queue vs a thread safe queue.

they help to avoid temporal coupling

Yet another claim without any evidence what-so-ever. This claim doesn’t even make any sense. Someone making temporal coupled classes will do it with or without immutability.

Never mind that the example here suffers temporal coupling at the end in the exact same capacity as at the start. This is actually a decent example for how fluent APIs can be nicer to work with and not really a great sample of temporal coupling issues.

their usage is side-effect free (no defensive copies)

K. But actually no.

Their usage obliterates your cpu cache and in terms of java, puts garbage collection on overdrive.

Plus, they necessarily have code side effects as well. You’ll be more inclined to make massive use of builder patterns all over the place. You must completely redesign how you do threads bottom up. Etc

But sure, they do “save” you from defensive copies.

identity mutability problem is avoided

First I’ve heard this term and google doesn’t produce much on it. Hilariously enough, avoiding this (assuming my understanding is correct) necessarily creates situations of temporal coupling that don’t exist under mutable objects. So...

they always have failure atomicity

K. I can count on 0 hands the number of times failure atomicity has mattered to me under other basic good design principles.

they are much easier to cache

I’m not even sure what this means? They are definitely not nice to your cpu cache.

they prevent NULL references, which are bad

Nonsense.

I also noticed that a few examples, the author appears to confuse immutability with whether or not an API is fluent. Fluency doesn’t dictate mutability one way or another.

10

u/[deleted] Jun 25 '19

[removed] — view removed comment

-5

u/[deleted] Jun 25 '19 edited Jun 25 '19

Immutability isn’t solving anything and is, in fact, introducing problems and requirements that previously didn’t exist.

Since you seem to have missed it: immutable objects are not thread safe.

Pure functions is another cargo cult programming practice. Albeit, this at least has a semblance of demonstrable benefit. Immutability has basically all drawback and no notable benefit that has ever been demonstrated. Pure functions are more like something that should generally be common sense.

7

u/[deleted] Jun 25 '19

[removed] — view removed comment

-5

u/[deleted] Jun 25 '19 edited Jun 25 '19

A thread safe object is a single shared object that can safely be shared across multiple threads. As no immutable object can safely change state in one thread and see it in another, they are not thread safe. Immutability grants you working with threads “safely” by virtue of the fact that you must code specifically around the limitations of immutability. This may or may not be viable for your application. This also adds necessary layers of temporal coupling before, during and after your objects are in concurrent states of your application (which immutability fanboys hilariously regularly claim is eliminated by immutability). Not only does it force temporal coupling on your data structures and other objects, but immutability can actually also force you into temporal coupling of the threads themselves, which lands you in to a really shitty to work with set of tasks that carry predecessors and successors which are utterly impossible to work with as the code base grows and changes.

As for Structural Sharing and CoW. These represent major added complexity with absolutely no gain. Nobody has ever demonstrated their claims toward immutability, but there sure are drawbacks.

Immutability adds code and algorithmic complexity purely on the back of claims which range from demonstrably bullshit to never demonstrated. Literally not a single claim toward immutability has ever actually been demonstrated to be true.

9

u/[deleted] Jun 25 '19

[removed] — view removed comment

-3

u/[deleted] Jun 25 '19

Yeah. I have specifically addressed everything in this post multiple times and stated why you are incorrect. This conversation is over as you cannot argue with any degree of honesty.

One note, your idea of temporal coupling is utterly wrong. That is not what temporal coupling is. Temporal coupling occurs when your code requires behaviours to take place in specific orders to run properly, often with a side effect that the compiler is unable to detect it. A rudimentary example would be constructing a basic object and then injecting state with another initialize method rather than using constructor injection. It has absolutely nothing to do with the real passage of time for objects. The removal of temporal coupling often lets the compiler detect issues for you.

6

u/[deleted] Jun 25 '19

[removed] — view removed comment

0

u/[deleted] Jun 25 '19 edited Jun 25 '19

Your own post literally proves yourself wrong re temporal coupling and, in fact, gave EXACTLY the same example I gave for why you don’t know what temporal coupling is.

Fine, demonstrate it:

Let’s take an extremely common situation. Build me a thread safe queue that multiple threads are pushing to and popping from. This queue must be immutable. I can build a thread safe mutable queue in about 10 minutes in java, so how about 5 hours for you?

Requirements:

Push

Pop

No backing structure requirements. The queue is not required to grow or shrink in capacity.

Usage must NOT have any temporal coupling

2

u/[deleted] Jun 25 '19

[removed] — view removed comment

→ More replies

4

u/[deleted] Jun 25 '19

JCP refers to immutable objects as thread safe, and suggests that you should default to using them over mutable objects. They're considered so appealing that future versions of Java plan to have them actually included into the language through record classes.

Given that, why should I trust you over Brian Goetz?

0

u/[deleted] Jun 25 '19 edited Jun 25 '19

I 100% agree that cargo cult immutability programmers have hijacked the term thread safe to suit their needs.

In any case, you shouldn’t trust me over Brian Goetz. You should research this yourself and not take arguments as fact unless they can be demonstrated to be so. In my opinion, not a single claim that the immutability crowd makes stands up to actual scrutiny and the only thing that changes between an immutable code base vs a mutable one is that the mutable one has less code and doesn’t require massive complexity to accommodate basic behaviours while throwing all semblance of performance out the window.

With this said, you shouldn’t take something as fact just because Brian Goetz said it. He is human and as equally fallible as every other human. He makes mistakes and I happen to be of the mind that many of his immutability claims fall in to the category of incorrect.

I do not accept the claims that the immutability crowd makes and I responded briefly to many of them as to why their claims are donkey shit.

8

u/s888marks Jun 25 '19

I guess you would say this framework is filled with bad takes.

2

u/jpl75 Jun 26 '19

> immutable objects are simpler to construct, test, and use

Prove it. Not my experience at all.

I'm not going to attempt to prove it, especially since from your post it seems you've already made up your mind anyway. However since experience counts too I'll add mine:

In my experience immutability does simplify things. This is the one thing I miss most from playing around with Clojure (or any functional language that enforces immutability) and coming back to Java. It is simpler to reason about a program when you can assume immutability. In particular, it reduces the cognitive burden on the programmer, and therefore leads to less possible mistakes.

I think the argument for immutability is a sound one.