3 ms·
Look at this C++ code: std::vector<Pair<std::string, MyInt>> s; s.push_back(Pair<std::string, MyInt>("a", MyInt(1))); s.push_back(Pair<std::string, MyInt
by shrimp_emoji 7y ago
Look at this C++ code:
std::vector<Pair<std::string, MyInt>> s;
s.push_back(Pair<std::string, MyInt>("a", MyInt(1)));
s.push_back(Pair<std::string, MyInt>("b", MyInt(2)));
s.push_back(Pair<std::string, MyInt>("c", MyInt(3)));
Gross. I'm being punished.
Look at this Rust code:
let mut s = Vec::new();
s.push(Pair::new("a", 1));
s.push(Pair::new("b", 2));
s.push(Pair::new("c", 3));
Both are statically typed, but one uses inference. It practically feels like Python everywhere except where type declarations matter most to me -- function signatures:
fn foo(x: f64, y: f64) -> Point {...}
In Python, those aren't very helpful.
def foo(x, y): ...
:c
- woud420 7y agoYou mean this C++ code? std::vector<std::pair<std::string, int>> s; s.push_back({"a", 1}); s.push_back({"b", 2}); s.push_back({"c", 3}); I mean let's compare apples to apples here.
- shrimp_emoji 7y agoDamn, I forgot about uniform initialization. D: That IS better than Rust since it migrates the type from n container members to just the 1 container. It doesn't seem possible to replicate that in Rust[0]. My Rust evangelism IS hurt by this. But its HP bar is big[1]. 0: https://news.ycombinator.com/item?id=10891892 https://news.ycombinator.com/item?id=10891892 1: https://www.reddit.com/r/rust/comments/bya8k6/programming_with_rust_vs_c_c/eqfcu0s?utm_source=share&utm_medium=web2x https://www.reddit.com/r/rust/comments/bya8k6/programming_wi...
- hhas01 7y ago“Look at this C++ code” YOU BASTARD NOW I’M BLIND! (In practice I’m pretty sure you’d typedef that, as much for maintainability as readability. Do agree though that type inferencing kicks the tar out of manifest types, at least up to the point the type inferencer gets lost.)