▲ | WalterBright 11 hours ago | |
> function arguments can be "in", "out", "inout", "ref", "scope", "return ref" - and combinations. None of them are required. What they do is provide enforcement of semantics that otherwise would have to be put in the documentation. And, as we all know, function documentation is always either missing, outdated or just plain wrong. For a (trivial) example:
vs:
In the latter, you know that `i` is being initialized by the function. In the former, you'll have to rely on the non-existent documentation, or will have to read/understand the foo()'s internals.`out` definitely is a win. Let's look at `scope`:
vs:
void foo(scope int* p) { static int* pg = p; } // compiler flags errorThis is most definitely a memory safety feature. |