Jump to page: 1 2
Thread overview
DIP1027 - Easy String Interpolation implementation
Oct 22, 2023
Walter Bright
Oct 22, 2023
Imperatorn
Oct 22, 2023
Juraj
Oct 22, 2023
Walter Bright
Oct 23, 2023
Juraj
Oct 23, 2023
Walter Bright
Oct 23, 2023
Adam D Ruppe
Oct 24, 2023
Imperatorn
Oct 24, 2023
Walter Bright
Oct 24, 2023
Imperatorn
Oct 24, 2023
Walter Bright
Oct 24, 2023
Adam D Ruppe
Oct 22, 2023
deadalnix
Oct 22, 2023
Imperatorn
Oct 22, 2023
Imperatorn
Oct 24, 2023
deadalnix
Oct 24, 2023
Imperatorn
Oct 24, 2023
duckchess
Oct 24, 2023
Walter Bright
Oct 22, 2023
Andrea Fontana
October 22, 2023
Several people asked for an implementation to try out, so here it is:

https://github.com/dlang/dmd/pull/15722
October 22, 2023
On Sunday, 22 October 2023 at 08:56:06 UTC, Walter Bright wrote:
> Several people asked for an implementation to try out, so here it is:
>
> https://github.com/dlang/dmd/pull/15722

I posted instructions for those wanting to try it out here:
https://forum.dlang.org/post/vthbbsubmxihmulthplo@forum.dlang.org
October 22, 2023

On Sunday, 22 October 2023 at 08:56:06 UTC, Walter Bright wrote:

>

Several people asked for an implementation to try out, so here

Thank you,
I have tried it out, and indeed had fun.
Here are some of the examples of the 'fun' I encountered.

Juraj


import core.stdc.stdio; // I can not bother with phobos right now

void main() {
    {
        int area_id = 51;
        int pod_to_drop_id = 69;

        eject_pods(i"medbay$area_id", pod_to_drop_id);
    }

    {
        string user = "root";
        string file = "stuff";

        delete_files_silently(i"/tmp/dummy_$user/$file", "/tmp/something_else");
        // Even better would be, to drop some tables form database....
    }

    {
        string name = "John";
        int anxlvl = 9000;
        string suggestion_msg = "Refer to the file and line number to save him!!!";

        log_error(2, i"$name's anxiety level is rising to level $anxlvl, suggestion:'$suggestion_msg'");
    }
}


void eject_pods(string area_name, int start_pod_idx, int count = 1) {

    enum SACRILEGE_VULCAN_AREA_NAME = "medbay%s"; // Spock insisted on %s so we have to keep it, Scotty

    if (area_name == SACRILEGE_VULCAN_AREA_NAME) autodestruct();

    for (int i = 0; i < count; i++) {
        printf("Dropping from %s pod : %d\n", area_name.ptr, start_pod_idx + i);
    }
}


void delete_files_silently(string some_param, string[] filepaths ...) {

    foreach (string fp; filepaths) {

        printf("Deleting file %s\n", fp.ptr);

        try {
            // delete_file(fp);
        }
        catch(Exception ex) {
            // Who cares, silence is gold.
        }
    }

}


void log_error(int level, string message, string file = __FILE__, int line = __LINE__, string[] more ...) {
    printf(i"[${%02d}level] $(file.ptr):${%04d}(line) $(message.ptr)\n");
}

void autodestruct() {}

October 22, 2023
On 10/22/2023 3:17 AM, Juraj wrote:
> On Sunday, 22 October 2023 at 08:56:06 UTC, Walter Bright wrote:
>> Several people asked for an implementation to try out, so here
> 
> Thank you,
> I have tried it out, and indeed had fun.
> Here are some of the examples of the 'fun' I encountered.

Yes, we've seen these before in the other threads, and I replied to them there.

October 22, 2023
On Sunday, 22 October 2023 at 08:56:06 UTC, Walter Bright wrote:
> Several people asked for an implementation to try out, so here it is:
>
> https://github.com/dlang/dmd/pull/15722

s/i/format!


October 22, 2023
On Sunday, 22 October 2023 at 19:35:46 UTC, deadalnix wrote:
> On Sunday, 22 October 2023 at 08:56:06 UTC, Walter Bright wrote:
>> Several people asked for an implementation to try out, so here it is:
>>
>> https://github.com/dlang/dmd/pull/15722
>
> s/i/format!

😁
October 22, 2023
On Sunday, 22 October 2023 at 19:35:46 UTC, deadalnix wrote:
> On Sunday, 22 October 2023 at 08:56:06 UTC, Walter Bright wrote:
>> Several people asked for an implementation to try out, so here it is:
>>
>> https://github.com/dlang/dmd/pull/15722
>
> s/i/format!

You forgot /g 😎
October 22, 2023

On Sunday, 22 October 2023 at 19:35:46 UTC, deadalnix wrote:

>

On Sunday, 22 October 2023 at 08:56:06 UTC, Walter Bright wrote:

>

Several people asked for an implementation to try out, so here it is:

https://github.com/dlang/dmd/pull/15722

s/i/format!

eject_pods(format"medbay$area_formatd", pod_to_drop_formatd);

:)

October 23, 2023
On Sunday, 22 October 2023 at 17:46:16 UTC, Walter Bright wrote:

> Yes, we've seen these before in the other threads, and I replied to them there.

Sorry for being repetitive, but as you made an implementation only after the DIP was rejected, I figured it would be beneficial to show some real examples.
I think they show in action one of the key reason why the DIP was rejected.

The last reply I was able to find, regarding this issue, was about logs not showing the correct file or number was a 'nothing-burger', I can not disagree more.

Anyway, all these silent bugs are not present in Adams implementation.
They end up as errors, as they, IMHO should (implicit conversion to a GC string being another option).
October 23, 2023
On 10/23/2023 1:34 AM, Juraj wrote:
> Sorry for being repetitive, but as you made an implementation only after the DIP was rejected, I figured it would be beneficial to show some real examples.

Thank you for posting them. Consider some more examples:

```
import std.stdio;

void main()
{
    writefln("hello %d", "betty"); // compiles just fine (exception at runtime)
    writeln("hello %s", "betty");  // compiles and runs!
}
```

I've made many mistakes like that. (Sorry, Betty!) I bet a lot of people have. There's no problem fixing them, as it's pretty obvious when a format string is in the output.

None of them resulted in memory unsafe code, and why would they? The generated strings are still checked for memory safety like any other code.

The result isn't type unsafe, either. The tuple elements are checked for type safety just like any other arguments.

Of course, printf isn't 100% checkable for memory safety (though D's checks plug most of those holes), so it's a bit unfair to blame DIP1027 for that. I did suggest that D's printf format checker could be enhanced to modify the arguments to make it memory safe, but that elicited no interest.

The fundamental issue here is that format strings are typed as strings. That issue is not going away. It is transferable to any attempt to use tuples as function arguments. There's a strong desire to use tuples a lot more in D (by adding the ability for functions to return tuples). Placing too much weight on this complaint would seem to seriously cripple use of tuples.

The complaint is also transferable to mixins. After all, mixins can generate arguments that are incorrect. mixins take string arguments, too, and it is up to the user of the mixin to ensure the string is formed properly.


> Anyway, all these silent bugs are not present in Adams implementation.

Adam strongly criticized my review of YAIDIP because that was not how his implementation worked. I spent several hours studying YAIDIP, and can't help being annoyed at the waste of time. I don't know how his implementation works, because there is no specification for it.

I await Adam writing a specification for it so I can review it.
« First   ‹ Prev
1 2