What type of `print` formatting do you prefer?

rempas rempas at tutanota.com
Tue Dec 21 10:07:56 UTC 2021


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.

The first one is Rust-like curly brackets as the placeholder. If 
you leave them empty the format is automatically chosen based one 
the type. Or you can specify a different format inside the curly 
brackets. Examples:

```d
print("My name is {}! Nice to meet you!\n", "Maria");
print("I am {} years old! And in binary, that is: {b:b}\n", 19, 
19);
```

In the first case, "Maria" is a string so it will get formatted 
automatically as a string. In the second case, 19 is a number so 
it will automatically get formatted as a signed number. But in 
the second placeholder is is specified that we want the value to 
be formatted as a signed number in the binary (2) base.

The second format type is C-like format using the "%" character 
and then one more character to specify the type. This is simple 
and pretty much everybody knows it so I'm not going to waste you 
time and make any examples.


Personally, I prefer the first way of doing things. The first 
time a learned about Rust (I don't use Rust tho just to be 
clear), I LOVED IT!!! It is so much clean and another things is 
that in pretty much any keyboard layout curly brackets will be 
closer and easier to press than the percent sign and to add on 
that, most people have curly brackets to automatically add the 
closing and so it will be blast to use!!!

Now I want to make clear that I'm mostly on this approach but I 
just wanted to ask in case someone can convince me that the 
C-like way is better. Well... I can see that one thing that is 
better with the C-like way is that you always see the formatting 
type so it may be better to some people. 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.

Thoughts?


More information about the Digitalmars-d mailing list