11 ms·
Perhaps not type declarations, but I think GP is onto something when it comes to Rust and how it handles types in a way that often lacks explicitness. There's a
by curun1r 9y ago
Perhaps not type declarations, but I think GP is onto something when it comes to Rust and how it handles types in a way that often lacks explicitness. There's a lot of Rust code where you have to have familiarity with an API to understand what's going on with the types.
As a for instance, let's say you have a function:
fn connect(addr: std::net::IpAddr) -> ... {
...
}
And it gets called:
connect("192.168.0.1".parse());
Unless you have a pretty good level of familiarity with the APIs involved, it's pretty difficult to reason about the types when looking at just the invocation of connect. You'd have to know that str::parse() will figure out what type it's supposed to be and, if it implements FromStr, it will call the from_str() function defined for that type to handle the coercion. That's a frustrating level of indirection for a beginner. And, since all of this is defined in the std library, it's also possible for library authors to similarly declare APIs that have this kind of indirect invocation where you only really understand what's going on if you've studied/memorized that API. I've often thought that a maze of From/Into and Deref coercions would be an excellent approach to the underhanded Rust competition because it's often so difficult to realize when that code is getting executed and it would be pretty easy to hide malicious code in functions that are executed implicitly.
It also doesn't help that a sizable portion of the Rust community believes console-based editors like vi and emacs are preferred and more advanced Rust IDEs are still early days and aren't able to help out much with situations like these.
It's not that I disagree with these types of language design decisions. I just feel this kind of lack of explicitness makes the language optimized for experienced users rather than beginners and helps give Rust it's deserved reputation for having a high learning curve.