DIP 1027---String Interpolation---Community Review Round 1

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Dec 11 15:27:08 UTC 2019


On Wednesday, 11 December 2019 at 15:13:20 UTC, jmh530 wrote:
> Because of the formatting options, I wouldn't lean too heavily 
> on Python's syntax. I think we should look to what other 
> languages do, but ultimately do what is right for D and 
> consistent with the language that is already there.

Sure, but as I pointed out you can do both. Just upgrade "%d" and 
"%f" to formatting objects and rewrite them.

So, if you want oldstyle you just write

f"%...d{variablename}"

and it will be turned into

f"{std.formatter.format_d(…), variablename}"

Having formatting objects is important for many reasons, one is 
localization. You need that for float and ints.  "3,14" vs "3.14" 
  or "1,000,000" vs "1'000'000" etc.

So you can do:

auto d = some_custom_formatter(…)

f"{d, variablename}...{d, somothervariable}"

*shrug*

printf style is only useful for logging and text file formats.

It does not work for GUIs or anything that is user facing. You 
need to be able to customize and provide your own formatters. 
(Just think currency  "100 USD" vs "100 SEK")



More information about the Digitalmars-d mailing list