3 ms·
I agree. The D program is cool, but pretty cryptic. A simple Rust version [0] is only 21 lines yet much more readable in my opinion. I'd take readability over a
by ibraheemdev 6y ago
I agree. The D program is cool, but pretty cryptic. A simple Rust version [0] is only 21 lines yet much more readable in my opinion. I'd take readability over a couple less loc anyday.
[0]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=72f9f0bddc75b1dc0bc1e5e37912952f https://play.rust-lang.org/?version=stable&mode=debug&editio...
- mhh__ 6y agoYou miss the point of the original one. When I wrote it the idea was that it is functionally pure and guaranteed to be such by the compiler (the annotation was removed because readln is not pure for obvious reasons). Most uses of loops break down to map, fold, or similar being able to use them cleanly can avoid a lot of bugs and API plasticity.
- Measter 6y agoThere's nothing stopping you from doing a functional style in Rust, neither: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=bd83ad8f79c7a5db63c31c156e95bf6b https://play.rust-lang.org/?version=stable&mode=debug&editio... There is a function on nightly that would make line 16 a little nicer, but oh well.
- littlestymaar 6y agoThe `op.parse()` at line 7 was a little hard to understand for me at the beginning. Only a few seconds after, I understood it was `op.parse::<f64>()` with the type parameter inferred from the type of `stack`, but I think it's easier to understand with the explicit type annotation (the turbofish) than without it.