4 ms·
Fair points, though many of these aren't as bad as they seem. > Violation of "explicit over implicit" rule in methods declarations: argument self/&self is impl
by Manishearth 11y ago
Fair points, though many of these aren't as bad as they seem.
> Violation of "explicit over implicit" rule in methods declarations: argument self/&self is implicitly omitted in call, but exist in signature. Because of this, for example, you can't use method of class as request handler in Iron, you need closure wrapper with same order and count of arguments. Pure ugliness;
You can call methods with explicit self too.
http://is.gd/dcLAZq http://is.gd/dcLAZq
In this case you would pass `Foo::bar` down to iron. Assuming the arguments are in the right order.
> and you can't catch them
You're not supposed to. Panics are to be used as less as possible; only for irrecoverable things or for application-level panicking.
> Nested structures is pain;
Could you expand on this point?
> Usage of safe code can lead to out-of-bounds errors, with thread panic (hello to vec macros).
It's idiomatic to use iterators as much as possible, or use the monadic indexing methods (which return Option).
- kbenson 11y agoI'm not sure why this was dead, but I vouched for it. Nothing here seems remotely worthy of flagging IMO.
- EugeneOZ 11y ago> You can call methods with explicit self too. Point is "signatures are different". You can't use this function in place where you need signature without &self. > You're not supposed to It makes life of web-servers harder. > Could you expand on this point? To parse JSON with nested objects you need to declare a lot of structures. When APIs are difficult, people even use code generators. > It's idiomatic It's not an argument. What work should work. Idiomatic or not - another question.
- Manishearth 11y ago> Point is "signatures are different". The signature is fn(&Foo, u8). If that's not in the right order, you can always put it in a closure -- this is not a Rust-specific problem. > It makes life of web-servers harder. I don't see why web servers need exceptions. You do have catch_panic if you want to prevent the application from ever crashing; that's what it's for (rewrapping fatal errors at the top level or preventing panics from leaking through FFI) > To parse JSON with nested objects you need to declare a lot of structures. Fair enough. I think there was a nested hashmap based JSON library somewhere?
- EugeneOZ 11y ago> you can always put it in a closure That's where I started. And it's Rust-specific problem because of implicit "self" argument, needed to send link to instance.
- Manishearth 11y agoNo, the implicit self can be made explicit in the caller. Or you can have a non-self function. This is no different from having a function which takes parameters in a different order from what's expected, and is not specific to Rust.
- EugeneOZ 11y agoNo, caller doesn't care about "self" and should not. It's Rust-specific ugliness and "different order of arguments" is absolutely not the same as "implicit first argument".
- Manishearth 11y agoI think I really need to see an example of what you're talking about. "implicit first argument" can be made explicit, we've established that. If the signature is still different that's an issue with order of arguments. If you don't want it to take self at all, well, it's a method, that's how methods work, they have a receiver. In all languages.
- EugeneOZ 11y agoI really wonder how it can be unclear. Iron expect method with signature "Fn(req: &mut Request) -> IronResult<Response>", it means you just can't use any method of instance, because all of them have crappy "&self" in signature (otherwise there is no point to make them methods of some object). And yes, you can add closure wrapper, add "move" keyword and satisfy all "move" requirements. But it's exactly what I'm talking about.