News for hackers. Stuff that matters.
Re:Implementing a Type-safe printf in Rust by hyperman1 on Friday August 14, 2020 @04:34AM (#24155376)
One thing i really miss from C's printf or Java's MessageFormat is the ability to change argument positions: Different languages can display the argument in different orders, and can have the format string in a resource bundle.

It is of course very hard to have type safety when the format string is in a resource bundle

Re:Implementing a Type-safe printf in Rust by dthul on Friday August 14, 2020 @05:01AM (#24155552)
The position of arguments is actually not required to follow the format string. From the documentation:

  println!("{1} {} {0} {}", 1, 2); // => "2 1 1 2"
But you are right, you cannot dynamically change the format string. If you need this facility, there is the runtime_fmt crate which will parse the format string at runtime instead of compile time. That of course means that it can fail at runtime if the format string does not match the arguments.
Re:Implementing a Type-safe printf in Rust by amelius on Friday August 14, 2020 @07:11AM (#24156420)
Why use numbers and not names, though?
Re:Implementing a Type-safe printf in Rust by dthul on Friday August 14, 2020 @07:15AM (#24156451)
You can!

  println!("{a} {c} {b}", a="a", b='b', c=3);  // => "a 3 b"
Re:Implementing a Type-safe printf in Rust by flohofwoe on Friday August 14, 2020 @05:49AM (#24155846)
POSIX printf() actually supports positional arguments:

https://www.godbolt.org/z/xG15M5

Both clang and gcc support this, but unfortunately not the Microsoft C compiler.

PS: actually, it does, just not in the normal printf call: https://docs.microsoft.com/en-us/cpp/c-runtime-library/print...

Re:Implementing a Type-safe printf in Rust by andralex on Saturday August 15, 2020 @10:08AM (#24168957)
D also supports POSIX positional arguments: https://dlang.org/library/std/format/formatted_write.html