by init1 · 7mo ago · 0 comments
This is false. For example in Ada you can write:
package Foo
type Bar is private;
procedure Initialize (Item : in out Bar);
private
type Bar is record
Baz : Integer;
Qux : Float;
end record;
end Foo;
Users of the Foo package know there is an opaque type called Bar. They can declare variables of the type, they can use the defined API to operate on it but they cannot reference the implementation defined private members (Baz, Qux) without compile errors. Yes Ada does give you the power and tools to in a very blatantly unsafe and obvious way cast it as another type or as an array of bytes or whatever but if you're doing stuff like that you have already given up.In JavaScript there are no such protections. For example if you have a module with private class Bar and you export some functions that manipulate it:
class Bar {
constructor() {
this.Baz = 420;
this.Qux = 1337.69;
}
}
export function Initialize() {
return new Bar();
}
In client code you have no issue inspecting and using the private values of that class: import { Initialize } from 'module';
let myBar = Initialize();
myBar.Baz = 42069; // works just fine
Object.keys(myBar).forEach(console.log); // you can iterate parameters.
myBar.Quux = 'Corge'; // add new parameters
delete myBar.Baz; // I hope no functions rely on this...
Using the private parts of Bar should 100% be a compilation error and even the most broken languages would have it at least be a runtime error. Lmao JS.[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Not to mention the fact that GP's issue only matters if you're using classes. You can define module-level variables and simply not export them and they are 100% private. Or, they can just define the variable inside of a function and protect it by a closure. I can't imagine writing multiple paragraphs of complaints about a language that I don't actually understand how to use.
However I don't really want to talk to you. You are rude.