5 ms·
Languages That Let You Assemble Software from Components
- majewsky 10y agoRe side-effect-free functions: If you want the semantics of the "mutating" keyword shown in the article, use C++ and use "const" for everything that's not being mutated. In my experience vigorous use of "const" helps avoid mistakes (like anything that makes the type system more expressive), but it ignores the elephant in the room: Side-effects to global variables (such as the state of a random-number generator) or external resources (files, the network, etc.). The submission touches on this in the "Sandboxing" section, but sandboxing only works for a certain class of applications that have a well-defined set of resources. How do you sandbox a root shell?
- kartickv 10y agoYes, const in C++ is interesting, though not as powerful as my proposal, for many reasons: - A const function can modify its arguments - ... and global variables, as you said. - You can always const_cast it away. - A non-const function doesn't identify which argument it mutates. As for sandboxing, I was talking about sandboxing a library within the app, which is a language-level issue. Not sandboxing the app as a whole, which is more like an OS-level issue. Perhaps your root shell uses a parser and you want to prevent bugs in it from crashing your shell...