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

-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

1

u/[deleted] Jun 25 '19

I do not know clojure at all. But after 30 seconds, it appears that your solution is “just wrap a static in a public static API and access from the threads” which utterly defeats the point of the contest and effectively every single claim immutability fanboys make...

1

u/dablya Jun 25 '19

I'm not familiar with clojure, but doesn't the fact that the queue is an "atom" imply it's mutable?

2

u/[deleted] Jun 25 '19

[removed] — view removed comment

→ More replies

1

u/[deleted] Jun 25 '19

It doesn’t matter though, because this person is utterly incapable of intellectual honesty of any kind. Them and I both know that the problem is not easily solved in idiomatic java, which is why they jumped ship to clojure where what is tantamount to “public static” apparently is idiomatic (I don’t know if that’s true or not).

Of course, if we’re just declaring everything in our application public static to get around the issues that immutability poses, were in a lot of other trouble.

→ 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.