DIP 1027--String Interpolation--Final Review Discussion Thread
FeepingCreature
feepingcreature at gmail.com
Thu Feb 13 06:34:59 UTC 2020
Replying from review thread:
On Wednesday, 12 February 2020 at 11:49:11 UTC, Juraj Mojzis
wrote:
> On Thursday, 30 January 2020 at 09:47:43 UTC, Mike Parker wrote:
>> This is the feedback thread for DIP 1027, "String
>> Interpolation".
>
> If
> writefln(i"I ate $apples and ${%d}bananas totalling $(apples +
> bananas) fruit.");
> gets rewritten as:
> writefln("I ate %s and %d totalling %s fruit.", apples,
> bananas, apples + bananas);
>
> Than for function:
> void my_err_log(string err_msg, string file, int line, int
> char) {...}
>
> called as:
> my_err_log(i"Error loading image $image_path.", src_file,
> src_line, src_char);
>
> gets rewritten as:
> my_err_log("Error loading image %s message", image_path,
> src_file, src_line, src_char);
>
> Results in an error but users will expect this to work.
>
> Worst case scenario is function that match:
> void draw_text(string text, int optional_x = 0, int optional_y
> = 0) {...}
> callad as:
> draw_text(i"Today is $day.$month.");
>
>
> For example, Phobos exceptions are mostly defined as :
> this(string msg, string file = null, size_t line = 0)
> this(string msg, string file = __FILE__, size_t line =
> __LINE__, Throwable next = null)
> etc.
>
> In my opinion, this is the fundamental flaw in the proposal.
Code that users expect to work resulting in an understandable
error is the second-best outcome there is.
Since we don't have strong AI yet, given a situation that the
compiler doesn't understand, this is pretty much the best result
we can hope for. D has made a deliberate decision to eschew
implicit conversions, so I don't think asking people to write
my_error_log(i"Error loading image $image_path".format, src_file,
src_line, src_char);
instead is a big ask.
Re draw_text(), this is a valid problem and more ammunition for
the 'i"" should return a templated struct' proposal, which would
neatly eliminate this issue.
More information about the Digitalmars-d
mailing list