foolang
foolang copied to clipboard
underscore methods as private
Goals
- Documentation, validation of assumptions.
- Compiler is able to reason about which methods are dead.
- Classes which have system object cannot have them stolen vial private methods.
- Interactive / development mode escape hatch.
Idea
Reject sends of _
-prefixed selectors to other than self
, #sendTo:
always rejects private selectors.
Thinking This Through
Is this enough for the compiler to reason about dead methods?
Yes. Since #_private
cannot be used to send a message via #sendTo:
, any _private
methods that don't have an entry from the send-graph are dead.
(Reasoning about non-private methods requires also knowing about source references to symbols, and references to interning mechanism.)
Does this allow subverting the authority of the system object?
(Can someone steal authorizing objects from things that were supposed to encapsulate them.)
No.
How to provide an interactive escape hatch?
...not clear.
Possibly it would be a better idea to instead have _private
methods interned in per-class symbol table?