4 ms·
> - Functions are not first class citizens - you can't return function as result; Of course you can: http://is.gd/YASF8T http://is.gd/YASF8T One issue is that
by masklinn 11y ago
> - Functions are not first class citizens - you can't return function as result;
Of course you can: http://is.gd/YASF8T http://is.gd/YASF8T
One issue is that closures don't really have their own types, so to return closures you need to use trait objects, which means dynamically-sized types, which means you have to box them
- Rust book on the subject: https://doc.rust-lang.org/book/closures.html#returning-closures https://doc.rust-lang.org/book/closures.html#returning-closu...
- Example of returning a boxed closure: http://is.gd/pJIqiu http://is.gd/pJIqiu
> Violation of "explicit over implicit" rule in methods declarations: argument self/&self is implicitly omitted in call, but exist in signature.
That's a debatable assertion, in a method call, the self/&self is the subject, the part before the dot.
> 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.
By "class" what do you mean? Because AFAIK it works on struct methods http://is.gd/xu6HRc http://is.gd/xu6HRc
> Rust has exceptions (panic), and you can't catch them
That's because Rust doesn't have exceptions, it has panics, they're not a general-purpose error-reporting or control-flow mechanism.
> lack of predefined values in structures
http://doc.rust-lang.org/std/default/trait.Default.html http://doc.rust-lang.org/std/default/trait.Default.html
> Usage of safe code can lead to out-of-bounds errors, with thread panic (hello to vec macros).
Safe rust doesn't mean no panics. `panic!` is safe rust.
- EugeneOZ 11y agoprintln() is not Iron request handler, you gave wrong example. Signature matters. I don't see how you can declare field if structure to have default value 65535, even with Default trait. I posted opinion not to argue and really frustrating to see downvotes for opinion. Make discussion more constructive.
- masklinn 11y ago> println() is not Iron request handler, you gave wrong example. Signature matters. println is not relevant here it only shows the result of the call, the point is that you can use a method as a function, I expect the issue is elsewhere (but not having used Iron, I wouldn't know where). > I don't see how you can declare field if structure to have default value 65535, even with Default trait. Implement Default then call it when instantiating struct: http://is.gd/2YSoKd http://is.gd/2YSoKd > I posted opinion not to argue and really frustrating to see downvotes for opinion. Make discussion more constructive. Er… I didn't downvote you? I just replied to some of your objections which I assume is what you expected?
- EugeneOZ 11y ago> the point is that you can use a method as a function And still: no. When signature is declared strictly (and in reality it's all cases except println and format), you can pass only function with matching signature. self/&self changes signature.
- EugeneOZ 11y ago> Implement Default then call it It's far from "default values in struct declaration". I mean this: struct X { i:u32 = 5, j:u64 }
- EugeneOZ 11y ago> That's because Rust doesn't have exceptions, it has panics, they're not a general-purpose error-reporting or control-flow mechanism. Oh, that's another minus: love to redefine well-known terms. Panics are exceptions, they behave exactly as exceptions, just unhandled. All other is just casuistry
- masklinn 11y ago> Oh, that's another minus: love to redefine well-known terms. Panics are exceptions The point of calling them panic is so they're not interpreted as exceptions and people used to exceptions-as-an-error-reporting-mechanism don't try to use them so. > they behave exactly as exceptions, just unhandled The "unhandled" part is exactly why they're not called exceptions.
- EugeneOZ 11y agoRedefining well-known terms gives nothing except confusion. And https://github.com/rust-lang/rfcs/pull/243 https://github.com/rust-lang/rfcs/pull/243 is another step in this direction (beside "?" idea). If usual errors handling will be called "exceptions", then we will have full mess with "Exceptions" term in Rust.
- scott_s 11y agoI don't think they've redefined any terms. When someone says a language "has exceptions", I think most people assume they can be caught as a way to recover from errors. Rust's panics are not that, so they used a different term to avoid confusion.
- EugeneOZ 11y agoThat someone just need to say "Rust has exceptions which can't be handled". Ridiculous enough, but it's true. They made bigger confusion, in my opinion. When even standard lib's code use panic as way to report about error, we can't say "nobody use panics as exceptions".