3 ms·
A valid point about knowing what the types mean, but even if you don't, it is at least immediately apparent which part is the type, and which part is the value.
by GordonS 7y ago
A valid point about knowing what the types mean, but even if you don't, it is at least immediately apparent which part is the type, and which part is the value.
I've only dabbled with rust, but I came across this very early on, and was baffled by the syntax. After further dabbling, I still can't see it and immediately know what the value is.
- labawi 7y agoAFAIK, syntax is: let variable_name [: type] = value[(i|u|f)bits]; In rust, 123l is written 123i64 or 123i32 (also 123_i32, or 1_2_3i32), depending on what 123l actually means. I don't actually use rust, but it seems very clear and obvious to me (obvious once you know the syntax above).
- GordonS 7y agoMeh, 123_i32 seems like a big improvement to me, but with the others, I just can't immediately grok it - it's having numeric digits as part of the type name that throws me. I realise of course that not everyone will feel the same.
- cyphar 7y agoC99 has effectively identical types in the standard library (uint8_t ... uint64_t, and ditto for int8_t ... uint64_t). There are very few modern C codebases where I haven't seen these used (personally I use them because it's much easier than remembering what is the minimum guaranteed size of unsigned long). The Rust ones have just slightly more terse names (which it's understandable to dislike, though I personally find the endless _t suffixes in C type names to be a bit annoying as well). And Rust's usize is basically uintptr_t.
- GordonS 7y agoSorry, I should have phrased that better; it's more like, having numeric digits as part of the type name that immediately follows the value throws me. So something like this (rust): `16i32` Compared to something like this (C#): `16i`
- steveklabnik 7y agoYou're not wrong, but also not comprehensive: it's not just variable names in that position, but full-on patterns.: let (a, b) = some_two_tuple; will introduce two varaibles, a and b, as respective halves of the tuple.