logoalt Hacker News

nmiloyesterday at 9:00 PM5 repliesview on HN

I will never stop hating on the orphan rule, a perfect summary of what’s behind a lot of rust decisions. Purism and perfectionism at the cost of making a useful language, no better way to torpedo your ecosystem and make adding dependencies really annoying for no reason. Like not even a —dangerously-disable-the-orphan-rule, just no concessions here.


Replies

hrmtst93837today at 6:16 AM

The orphan rule is annoying. It's also one of the few things stopping trait impls from turning crate boundaries into a knife fight, where two deps both decide they own the same foreign type and the compiler has no sane answer once both impls are in the graph.

Rust pays for coherence up front with wrapper types and boilerplate, which is ugly, but the alternative is the kind of ambient monkeypatching that makes APIs hard to reason about once a codebase gets large. A narrow escape hatch might be worth trying, but a global 'disable it' switch sounds like repo poison.

show 1 reply
simonaskyesterday at 10:33 PM

I think there are legitimate criticisms of Rust that fall in this category, but the orphan rule ain’t it.

In most other languages, it is simply not possible to “add” an interface to a class you don’t own. Rust let’s you do that if you own either the type or or the interface. That’s strictly more permissive than the competition.

The reasons those other languages have for not letting you add your interface to foreign types, or extend them with new members, are exactly the same reasons that Rust has the orphan rule.

kryptisktyesterday at 10:59 PM

It's not a restriction born out of purity, notably uncompromising Haskell allows orphan instances.

voxlyesterday at 10:31 PM

Good for better, better for us. Rust is choke full of hard compromises and reactionary subcultures. Just recalling ? alone.

irishcoffeeyesterday at 10:19 PM

Go: error handling stinks. Generics would be dope.

Rust: if you spent 3 weeks understanding the syntax and borrow-checker, here are all of the other problems, and the list keeps growing.

Man this cracks me up.