What type of `print` formatting do you prefer?

Paul Backus snarwin at gmail.com
Wed Dec 22 01:40:02 UTC 2021


On Tuesday, 21 December 2021 at 10:07:56 UTC, rempas wrote:
> Before I make my library, I want to first ask what type of 
> formatting you guys prefer between the two I'm going to show 
> you.

I personally find the Python/Rust style (with `{...}`) to be more 
readable than the C style (with `%...`), but both are ok.

> Also the design of the Rust-like way will be harder to 
> implement (not that I mind) and it will need discussion. For 
> example we are using "t: type" to specify the type, "b: base" 
> to format as a signed number and specify the base, "f: number" 
> to format as a float and specify the number of floating points 
> etc.

One of the big advantages of C's format-string syntax is that its 
conventions are largely shared across programming languages. For 
example, if you know what `%d` means in C, then you also know 
what it means in Java, Go, D, and any other language that uses 
C-style format strings.

If you are planning on designing a new `{}`-style format-string 
syntax, I would strongly recommend aiming for consistency with 
other languages like Python, Rust, and C# that use `{}` for 
string formatting. For example: all of those languages use `{0}` 
to insert the first parameter, `{1}` to insert the second, and so 
forth, so your new library should do the same.


More information about the Digitalmars-d mailing list