
Languages That Let You Assemble Software from Components - kartickv
https://kartick-log.blogspot.com/2017/03/languages-that-let-you-assemble.html
======
majewsky
Re 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
Yes, 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...

~~~
majewsky
Ah, that makes sense.

Re const_cast: At least, you can now find problematic code with a grep to
focus on that during code audits, much like with Rust's "unsafe" keyword.

~~~
kartickv
Agreed.

