3 ms·
My apologies, but that's what's been explained. Something to the effect of "it's best that people document/annotate their types, so we require it." Your descri
by MichaelGG 10y ago
My apologies, but that's what's been explained. Something to the effect of "it's best that people document/annotate their types, so we require it."
Your description of contracts in Rust vs other languages isn't reflective of how they can be used. With global inference, nothing prevents a programmer from deciding where the major boundaries of his program are and annotating where desired. This not only provides the benefits of both worlds, but allows the author to decide where the contract and documentation goes.
Nothing is gained by requiring the programmer to annotate every little helper function, nested or otherwise. And for people just playing around, it brings a significant barrier. They must not only sort of grasp how the borrow system works, they must be able to write a flawless annotation to boot.
At worst, lack of annotations should be a warning (the warning can include the inferred type!), like the casing/naming style ones. Perhaps with an option for public/exported functions only.
(Sorry if my tone comes off hostile; not my intention.)
- kibwen 10y ago> "it's best that people document/annotate their types, > so we require it." That may be how people interpret it (I'd be surprised to find that line in any official source), but the reason for this choice was ultimately technical, not philosophical. Having function signatures be the ultimate source of truth means that the typechecker can ignore function bodies entirely, which has large implications for the design of the type system and the layout of the compiler pipeline, and more importantly this feature enables fine-grained incremental recompilation at the function level (i.e., if the body of a function changes but its signature does not, then the compiler knows that consumers of that function do not need to be recompiled and can skip an enormous amount of work (assuming that inlining is minimal, which is indeed the case in debug mode, where incremental recompilation is intended to shine)). We're not taking advantage of incremental recompilation yet, but it (along with speeding up the compiler in general, as corroborated by the survey) is the primary goal of the compiler team this year (the prerequisite overhaul of the compiler middle-end is just about to land: https://github.com/rust-lang/rust/milestones/Launch%20MIR%20into%20Orbit https://github.com/rust-lang/rust/milestones/Launch%20MIR%20... ).
- MichaelGG 10y agoNot official, but a Rust team member: "it's generally regarded as best practice to write out the types of your functions, hence Rust's choice here. ... Rust follows 'explicit over implicit'"[1] If it's a technical limitation then that's far more understandable. I've just not heard this explanation until now -- not that I really was seeking it I suppose. Thank you. 1: https://news.ycombinator.com/item?id=8321443 https://news.ycombinator.com/item?id=8321443