3 ms·
It would actually be such an amazing language if it wasn’t so verbose. There are so many places where more concise syntax wouldn’t even hurt safety and they for
by alphanullmeric 4y ago
It would actually be such an amazing language if it wasn’t so verbose. There are so many places where more concise syntax wouldn’t even hurt safety and they forgo it anyways. But here we are, where macros are required for a hello world.
- JoshTriplett 4y ago> There are so many places where more concise syntax wouldn’t even hurt safety and they forgo it anyways. Can you give some examples of this? If there are ways we could simplify the language without hurting existing use cases, we should consider doing so.
- alphanullmeric 4y agoNo default arguments, named parameters, variadic functions and generics, no C-style arrow operator, the whole default trait thing (why can’t you shorten it to just `..`?). And a bunch of awful reasoning to defend these decisions. Named function arguments are bad but `Iterator<Item=T>` is fine? Default arguments are bad but default trait implementations are fine? Something something implicit behaviour but type inference is ok? It’s to the point where idiomatic rust means writing a three different structs and enums to call a function.
- spoiler 4y agoYou don't technically need the macro to print hello world. However, the macro is useful due to format strings, which are also type-checked (eg to checks if the args implement `Display` or `Debug`, etc). The good thing about the default hello world example is that it introduces you to both language features without being overwhelming (IMO). You can read more about format strings here: https://doc.rust-lang.org/std/fmt/ https://doc.rust-lang.org/std/fmt/
- tialaramex 4y agoRight, the canonical C "Hello, World!" uses C's formatted print, even though obviously it's not formatting anything, so it seems appropriate for Rust to do the same. It would be more impressive if Rust had an actual type checked variadic print format function like C++ 23's std::println - nobody should be under any false impression about how impressive that feature is, but the type safe macro is effective, that'll do pig.
- spoiler 4y agoI think Rust is probably working towards features like this. They've added partial const generics only a year ago, and I'm not sure what the stance on variadic functions is, but unless they're considered bad, they might get added too. AFAIK C++ does format string parsing at runtime (as you need to provide a parser function), but maybe it can be made constexpr? I've not written C++ for over a year now so my fluency is fleeting a bit
- bobbylarrybobby 4y agoI can't think of a better way to do compile time, zero allocation printing than with a macro. Runtime format strings are so ugly and fragile.