logoalt Hacker News

jqpabc123last Sunday at 1:10 PM3 repliesview on HN

private data, convenience

Which can be easily achieved without OOP.


Replies

pjmlpyesterday at 6:41 AM

In fact, to a certain point of view, OOP is a way to have modules bind to variables, and being extensible.

show 1 reply
pitchedyesterday at 5:38 AM

That upfront convenience here leads to a long tail of job security when it inevitably goes spaghetti. Win-win!

show 1 reply
Blikkentrekkeryesterday at 12:10 PM

It's really not clear whether Rust does it or not and it just sidesteps the issues by calling them “structs” and “enums” but fields can be private of course.

Scheme Structs are rather interesting, when you define a struct the language by default also exports getter and setter functions with a predictable name though you can override the default name to give them any name, privacy is simply created by choosing to not export these getter and setter functions from the module.

Privacy on the module level rather than on the class level is a far better pattern to be honest. As in other classes defined in the same module can still have access to them.