3 ms·
edit I see I'm too late, Walter already answered this. I'll leave this here anyway. I don't think D's writefln is getting any special treatment from the compil
by MaxBarraclough 6y ago
edit I see I'm too late, Walter already answered this. I'll leave this here anyway.
I don't think D's writefln is getting any special treatment from the compiler. It seems to use D's compile-time features to perform the check.
https://github.com/dlang/phobos/blob/v2.093.0/std/stdio.d#L4095 https://github.com/dlang/phobos/blob/v2.093.0/std/stdio.d#L4...
- AnIdiotOnTheNet 6y agoZig does it in a similar way, using the compile time type information available to all Zig code, and is in fact implemented in the std library. No magic necessary.
- renox 6y agoBut both fail short to Python/bash.. format strings where you can have "in place" reference to variable which IMHO is much more readable.
- ben-schaaf 6y agoI completely agree that string interpolation is often superior to a format string, but it's important to note that they are not equivalent. String interpolation is generally evaluated in-situ and has full access to the local scope. Format strings on the other hand can be passed around and manipulated (even at compile-time) and can only ever access the data they're formatted with. strftime and strptime are a good example of a format string usage that can't be replaced by string interpolation in python. D also has the capability of implementing string interpolation using mixins - though the resulting code isn't quite as neat.
- CyberDildonics 6y agoFormatting text output is not often a problem in the larger scope of a program, but having performance bottlenecks can be.
- WalterBright 6y agoI did write a proposal for "in place" reference (i.e. string interpolation) but could not reach consensus with the D community for it.