DIP 1027--String Interpolation--Final Review Feedback Thread
FeepingCreature
feepingcreature at gmail.com
Thu Feb 13 05:46:15 UTC 2020
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.
Errors are fine. If you write wrong code and get an error... I
don't know what the compiler could do about that. "Users expect
something to work but it doesn't" is not universally a bug - this
happens all the time, and there's nothing to be done until we get
strong AI and can do DWIM.
I don't think it's a crippling ask to make users write
my_error_log(i"Error loading image $image_path".format,
src_file, src_line, src_char);
IMO it's still a hefty improvement on the status quo.
More information about the Digitalmars-d
mailing list