🔥 New blog post: JS private class fields considered harmful

Today I am mourning. What am I mourning? Encapsulation. At least in my projects.

As a library author, I’ve decided to avoid private class fields from now on and gradually refactor them out of my existing libraries.

Why did I make such a drastic decision? Read on.

lea.verou.me/2023/04/private-f

Follow

@leaverou

I share your pain. I have been so much time hammering the idea that you must encapsule and hide things as much as you can...

At core, it is a clash between two totally opposite paradigms: the God paradigm (put all the state at one place: state manager, root component... And that place decides to whom it bestows knowledge) and the need-to-know paradigm (each piece of information has an owner, and you must avoid anybody else having it, as much as you can). Vue information flow from parent to children is only a variant of the God one, with a God who delegates.

Object orientation is based on the need-to-know. Vue is based on the God one.

It is the same as wanting a container to fit its content, and the content to fit the parent. You can't really have both without getting hurt.

And we have been learning this the slooooow way.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.