It was a rough example but the idea is thinking in terms of data in and data out and how can it be done. Here the train of thought first would be: do I have the right data form for the thing I am doing? Here we have:
{company: {staff: [{..., pets: []}]}}
And what we want to do is to produce a list of all the pet cats with its owner name.
[{cat: "bla", owner: "bla"}...]
or
[{owner: "bla", cats:[...],...}, ...]
So I guess what Im trying to explain is that what is important is the change in the way of thinking about problems. When you think of them as data transformations there is a whole lot of possibilities that open. And it is not more expensive because you even have things like transducers. When you abstract away the iteration you are able to compose much more easily.
And to answer your question directly in my example the print function would print for each cat belonging to the staff which is not great flattening would be more elegant. What I wanted to convey is thinking in data transformations and abstracting away the implementation details of the iteration.
Because it is easier to reason about data transformations. Here when I see loops and conditionals it is confusing because anything could be happening. company.staff.filter(notCats).forEach(printMessage) has more information of what is going on for example imho. But there is a lot more to it.
Also remember here the promise is that the data you are talking about wont suddenly change underneath not that the reference 'is up to date".
It is not a solution for change in time it is a solution for taking change in time out of the equation when we don't need to talk about that. With immutable ds when we talk about data we are just talking about exactly that and time is taken out of the picture. Its called immutable because now you are talking about facts and not the representation in time of those facts. Because now we are talking in versions so it does not make sense. The thing is this data is a snapshot so you are not guaranteed to have the most up to date snapshot. And that's ok because precisely here we take change in time out of the question in order to be able to talk more precisely about the data. Tracking change in time is another story.
So for example you could have things like react. There you have snapshots of the world updating. When you talk about the data it is immutable but then you change it and update the mutable variable where you are keeping change in time.
Think of it as versioning for your data. So instead of referring to some data structure by its general concept with immutable data structures we are a lot more specific with respect to the identity represented by the name, here the name represents a version.
This is useful because, for example, you stop having the "unmanaged references" you were talking about because now since you are pointing to a version of the data and not the data itself you can be sure of what you are talking about.
Immutability is not the fact that something can not change in this case. It has more to do with the identity of a value. Every time you change anything inside the data structure you get a new reference, that is it!
We should rename object oriented programing to bureaucrat oriented programming. I always think that the reasoning that led to develop the aberration of OO is the same that creates bureaucratic nonsense.The want of making people replaceable through bureaucracy so that the programmer as a human being can be removed from the picture plus all the other bureaucratic thinking nonsense leaked to the design of the language. Its funy how ridiculous we are, pretending something all the tme.
I think that a lot of people here are forgetting that a project is whatever you make a project to be. It does not need to be operated like a bureaucratic profit seeking corporation. The problem is that the corporate world leaks their madness into our private lives. Just do whatever you want and have fun. Remember that you can choose any type of societal model to structure your project. And most importantly you are free to walk away at any time. But there exist two things here the real project and the social avatar of the project and how the people on the project interact with each other. What belongs to whom? and does it matter? Sub specie aeternitatis this whole thing feels like an effing Herzog movie. Please don't let yourselves get carried away by this nonsense. Like whats the effing point here Fitzcarraldo? I mean seriously people, as a humanity, where are we going so fast that we can't wait to get there and why don't get there with joy?
Love, care and a nurturing social structure wihle developing as a child is what keeps a child healthy. What I meant was that self worth is tied with validation from authority. A sense of inadequacy is always fomented and all the other nonsense of the social experiments we call schools.And at some point you need to wake up to the fact that in a way its just a big theater. That's why you have theories like Rousseau's social contract. You need to answer to the question why are we doing this again?
In some ways it has to do with the fact that people are educated to have a need for validation from an authority and several other ways of thinking that are completely counterproductive.
I think it has to do with the idea of work. Some people associate work with discomfort and feel guilty if they have fun so they transform their projects on uncomfortable work like things.
The beauty of it is that once you craate something and you share it you have already contributed something. I think that what you feel has more to do with your educaction. Like I said it is all in your head and you do that to yourself.
His point is that if you end up like that it's because you don't recognize freedom when you see it. Its like that movie when the monkey does not go out of thee cage even if opened. Because its your project and you can do whatever you want. Its all in your head.