Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A thing that helps with Rust, in my opinion, is that the language is statically typed and people mostly write functions. That makes it easy to glue the pieces together in my head. So even if the documentation isn't great, I can find a way to do what I want.


Also, people don't overuse polymorphism like they do in Java and C#.


There's still lots of polymorphism in Rust. Take for example the way reqwest handles HTTP headers. Reqwest cares that it's technically possible (albeit a bad idea) to write arbitrary bytes into an HTTP header name even though those bytes are ASCII case crushed. This being understood, and Rust's strings necessarily being UTF-8 and not arbitrary bytes, a header's name might not be a string in Rust (though of course the vast majority are) and so Reqwest carries around a whole marker type for things-that-might-be-plausible-header-names, knowing that all any non-bad-guys will care about is a few simple ASCII strings but needing to correctly handle much more.

The two obvious things work, if you say the name of a header, you get that header, and there are constants like HOST defined for the most common headers to avoid typos, but you can do crazy stuff, and importantly if a hostile peer sends you crazy stuff Reqwest promises to cope.

Maybe it's that Rust's polymorphism is more explicit through Traits.

If Pigeon, Duck and Emu are all Birds, and further more Animals in C++ it's unclear what exactly this Bird superclass does for me, still less Animal or when I, knowing I have a Pigeon here, should consult the documentation for Bird and/or Animal rather than or in addition to that for Pigeon.

Whereas not only does the Emu not implement Fly, I can feel comfortable guessing that the code implementing Fly generically or for my Pigeon is unlikely to be related to my problem that this Pigeon says "quack" and I should instead look closely at the AnimalSound trait, given away by the fact I had to explicitly name that trait to get the "quack" noise from the pigeon.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: