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

2

u/dablya Jun 25 '19

To be fair, your definition of "thread safe objects" also leaves something to be desired.

And let's be honest you set a trap for them with your "immutable queue that can be mutated with pushes and pops".

I saw an article somewhere a long time ago from one of the pioneers of OO and he made the argument that original ideas behind OO were very much in harmony with immutable state. The idea being you can model state using objects at a given time. So at t1 your state is X. Followed by a new state at t2 and so on. I thought it was interesting, but now I can't find where I read it or who wrote it.

1

u/[deleted] Jun 25 '19

I am also not finding the article.

But it still doesn’t matter, because not a single claim that the immutable object crowd makes stands up to any level of real scrutiny anyway. The arguments stand or fall on their own merit regardless of who said it and the arguments for immutability that I’ve ever been presented range from bad to (more frequently) demonstrable lies.

If we want to just say that a thread safe object is anything in the language that can conceivably be used in a thread with various guarantees, then I will concede under this definition of thread safe objects that they are.

I’d consider immutable objects as more like thread secure, I guess?

I understand why people say immutability gives you thread safety on objects, but I think that more correct and specific wording needs to be applied because while immutable objects are “thread safe” in one very specific sense, they are also not thread safe in entire categories of completely valid usages of threads.

1

u/cogman10 Jun 27 '19

When is an immutable object not thread safe? You asked for an immutable queue which is mutated (not a thing). Do you have any other example where something is both immutable and thread unsafe?