3 ms·
> In a systems language, it's important to know if you're passing around things by value or reference. I'm not sure that distinction should be always in your f
by cousin_it 10y ago
> In a systems language, it's important to know if you're passing around things by value or reference.
I'm not sure that distinction should be always in your face though. Systems or no systems, you almost never want to pass a number by reference or pass an array by value.
- masklinn 10y ago> Systems or no systems, you almost never want to pass a number by reference It does occur for generic reference-based API though (e.g. many iterators) And you'd want to know whether you're passing a string or a vector by reference of value though, especially with affine types.
- cousin_it 10y agoWhy would you ever want to copy a string when passing it into a function?
- dbaupp 10y agoNote that "pass by value" isn't a copy in a language with affine types like Rust. I'm not sure passing everything by reference probably would gain much in a systems programming language in the vein of Rust: one would still need some syntactic method to distinguish between shared ("immutable") and non-shared ("mutable") references. Also, Rust-style static reasoning cares about things actually being pointers, to allow returning references safely. Lastly, being able to move things around is important too, it is a major part in Rust creating zero-overhead abstractions. I'm not sure exactly how MLKit works, but I glanced over https://github.com/melsman/mlkit/blob/master/doc/mlkit.pdf https://github.com/melsman/mlkit/blob/master/doc/mlkit.pdf and it seems to me that its regions are somewhat less static and that it doesn't attempt to handle concurrency. I could be wrong on both counts!
- cousin_it 10y agoI think you could have mut visible at the language level, but otherwise have all parameter passing look and feel like Java, without any pointer noise or implicit copying.
- masklinn 10y agoHow would lifetimes work? Java & al get away with it because they don't reify lifetimes and the concepts of reference and value are moved at the type level (and they don't use affine types).
- cousin_it 10y agoFrom looking at research languages with similar systems (Mezzo, LinearML...) none of them seem to have pointer noise. I might be missing something though.
- masklinn 10y agoIn Rust, passing a string by value is a move, and it won't copy the backing buffer at most it copies the stack structure (24 bytes) and possibly not even that (depending on the way it's used). As to why, well because the function asks for it, either because it generically works on values, or because it consumes the string to avoid copying its internal buffer (e.g. https://doc.rust-lang.org/std/string/struct.String.html#method.into_bytes https://doc.rust-lang.org/std/string/struct.String.html#meth...), or whatever other reason. Either way that's a completely valid use.