| ▲ | flohofwoe 2 hours ago | |
I can show more code examples instead: E.g. notice how here in Rust each nested struct needs a type annotation, even though the compiler could trivially infer the type. Rust also cannot initialize arrays with random access directly, it needs to go through an expression block. Finally Rust requires `..Default::default()`: https://github.com/floooh/sokol-rust/blob/f824cd740d2ac96691... Zig has most of the same issues as Rust, but at least the compiler is able to infer the nested struct types via `.{ }`: https://github.com/floooh/sokol-zig/blob/17beeab59a64b12c307... I don't have C++ code around, but compared to C99 it has the following restrictions: - designators must appear in order (a no-go for any non-trivial struct) - cannot chain designators (e.g. `.a.b.c = 123`) - doesn't have the random array access syntax via `[index]` > ...like a pretty minor syntax issue... ...sure, each language only has a handful minor syntax issues, but these papercuts add up to a lot of syntax noise to sift through when compared to the equivalent C99 code. | ||
| ▲ | phicoh 38 minutes ago | parent [-] | |
In Rust you can do "fn new(field: Field) -> Self { Self { field } )" This is in my experience the most common case of initializers in Rust. You don't mention one of the features of the Rust syntax, that you only have to specify the field name when you have a variable with the same name. In my experience, that reduces clutter a lot. I have to admit, the ..Default::default() syntax is pretty ugly. In theory Rust could do "let x: Foo = _ { field }" and "Foo { field: _ { bar: 1 } }". That doesn't even change the syntax. Its just whether enough people care. | ||