Jump to page: 1 29  
Page
Thread overview
[OT] C# can do all the interpolated strings now
Dec 08, 2021
WebFreak001
Dec 08, 2021
Adam D Ruppe
Dec 08, 2021
Dennis
Dec 08, 2021
WebFreak001
Dec 08, 2021
kdevel
Dec 09, 2021
zjh
Dec 09, 2021
WebFreak001
Dec 09, 2021
bauss
Dec 09, 2021
kdevel
Dec 09, 2021
forkit
Dec 10, 2021
forkit
Dec 10, 2021
forkit
Dec 08, 2021
bachmeier
Dec 08, 2021
bauss
Dec 09, 2021
deadalnix
Dec 09, 2021
Adam D Ruppe
Dec 09, 2021
mork
Dec 09, 2021
Kagamin
Dec 10, 2021
Kagamin
Dec 09, 2021
deadalnix
Dec 10, 2021
Kagamin
Dec 09, 2021
Adam D Ruppe
Dec 09, 2021
deadalnix
Dec 09, 2021
WebFreak001
Dec 09, 2021
WebFreak001
Dec 09, 2021
WebFreak001
Dec 09, 2021
Adam D Ruppe
Dec 09, 2021
Adam D Ruppe
Dec 12, 2021
Q. Schroll
Dec 13, 2021
Q. Schroll
Dec 13, 2021
Adam D Ruppe
Dec 14, 2021
Adam Ruppe
Dec 14, 2021
Bruce Carneal
Dec 17, 2021
Patrick Schluter
Dec 17, 2021
bauss
Dec 17, 2021
Patrick Schluter
Dec 18, 2021
Walter Bright
Dec 09, 2021
deadalnix
Dec 09, 2021
Bruce Carneal
Dec 09, 2021
WebFreak001
Dec 09, 2021
deadalnix
Dec 09, 2021
Adam D Ruppe
Dec 09, 2021
deadalnix
Dec 09, 2021
Adam D Ruppe
Dec 09, 2021
deadalnix
Dec 10, 2021
Walter Bright
Dec 09, 2021
Kagamin
Dec 10, 2021
Rumbu
Dec 17, 2021
Imperatorn
Dec 17, 2021
bachmeier
Dec 18, 2021
Imperatorn
Dec 18, 2021
bauss
Dec 18, 2021
Imperatorn
December 08, 2021

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated#compilation-of-interpolated-strings

>

Beginning with C# 10, when an interpolated string is used, the compiler checks if the interpolated string is assigned to a type that satisfies the interpolated string handler pattern

Usage example: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/interpolated-string-handler

What do you think of these extended interpolated string expressions? I think these would fit well into D, and could give some new motivation now that we have had our interpolated strings DIPs rejected once and withdrawn once.

December 08, 2021
On Wednesday, 8 December 2021 at 10:46:31 UTC, WebFreak001 wrote:
> give some new motivation now that we have had our interpolated strings DIPs rejected once and withdrawn once.

there's another good document mostly written but waiting on john and andrei to take the next step.........
December 08, 2021
On Wednesday, 8 December 2021 at 12:55:02 UTC, Adam D Ruppe wrote:
> there's another good document mostly written but waiting on john and andrei to take the next step.........

https://github.com/John-Colvin/YAIDIP
December 08, 2021

On Wednesday, 8 December 2021 at 10:46:31 UTC, WebFreak001 wrote:

>

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated#compilation-of-interpolated-strings

>

Beginning with C# 10, when an interpolated string is used, the compiler checks if the interpolated string is assigned to a type that satisfies the interpolated string handler pattern

Usage example: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/interpolated-string-handler

What do you think of these extended interpolated string expressions? I think these would fit well into D, and could give some new motivation now that we have had our interpolated strings DIPs rejected once and withdrawn once.

I'm not gonna judge anyone, but System.Runtime.CompilerServices.DefaultInterpolatedStringHandler might be classified by some as verbose.

December 08, 2021

On Wednesday, 8 December 2021 at 13:51:53 UTC, bachmeier wrote:

>

On Wednesday, 8 December 2021 at 10:46:31 UTC, WebFreak001 wrote:

>

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated#compilation-of-interpolated-strings

>

Beginning with C# 10, when an interpolated string is used, the compiler checks if the interpolated string is assigned to a type that satisfies the interpolated string handler pattern

Usage example: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/interpolated-string-handler

What do you think of these extended interpolated string expressions? I think these would fit well into D, and could give some new motivation now that we have had our interpolated strings DIPs rejected once and withdrawn once.

I'm not gonna judge anyone, but System.Runtime.CompilerServices.DefaultInterpolatedStringHandler might be classified by some as verbose.

Well in theory you only need to type DefaultInterpolatedStringHandler if you have a using statement in top of your file like "using System.Runtime.CompilerServices;".

December 08, 2021

On 12/8/21 5:46 AM, WebFreak001 wrote:

>

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated#compilation-of-interpolated-strings

>

Beginning with C# 10, when an interpolated string is used, the compiler checks if the interpolated string is assigned to a type that satisfies the interpolated string handler pattern

Usage example: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/interpolated-string-handler

What do you think of these extended interpolated string expressions? I think these would fit well into D, and could give some new motivation now that we have had our interpolated strings DIPs rejected once and withdrawn once.

No, I think the interpolation tuples that Adam and I proposed, and the proposal from John and Andrei are much simpler and straightforward.

Just look at the C# requirements!

"We introduce a new handler pattern that can represent an interpolated string passed as an argument to a method. The simple English of the pattern is as follows:

When an interpolated_string_expression is passed as an argument to a method, we look at the type of the parameter. If the parameter type has a constructor that can be invoked with 2 int parameters, literalLength and formattedCount, optionally takes additional parameters specified by an attribute on the original parameter, optionally has an out boolean trailing parameter, and the type of the original parameter has instance AppendLiteral and AppendFormatted methods that can be invoked for every part of the interpolated string, then we lower the interpolation using that, instead of into a traditional call to string.Format(formatStr, args)."

Ugh...

-Steve

December 08, 2021

On Wednesday, 8 December 2021 at 13:28:33 UTC, Dennis wrote:

>

On Wednesday, 8 December 2021 at 12:55:02 UTC, Adam D Ruppe wrote:

>

there's another good document mostly written but waiting on john and andrei to take the next step.........

https://github.com/John-Colvin/YAIDIP

ah yeah I couldn't remember where that one was, I only found the 2 other DIPs while googling.

I like the overall idea but there is one thing that feels a little bad with that: If I have a function

void foo(string header, string docs);

I can't just pass

foo(i"$name's Website", i"Welcome on $name's Website");

because interpolated strings are not strings. I would need an extra .text call.

I think it would be easier on users if it was all one big struct like InterpolatedString!(args here...) - not being able to be multiple arguments at once

Otherwise if you had void foo(T...)(T args) you could no longer iterate over every argument individually, but need to keep track of state to know whether you are in an interpolated string. (and you don't know when it ends)

December 08, 2021

On 12/8/21 10:39 AM, WebFreak001 wrote:

>

On Wednesday, 8 December 2021 at 13:28:33 UTC, Dennis wrote:

>

On Wednesday, 8 December 2021 at 12:55:02 UTC, Adam D Ruppe wrote:

>

there's another good document mostly written but waiting on john and andrei to take the next step.........

https://github.com/John-Colvin/YAIDIP

ah yeah I couldn't remember where that one was, I only found the 2 other DIPs while googling.

I like the overall idea but there is one thing that feels a little bad with that: If I have a function

void foo(string header, string docs);

I can't just pass

foo(i"$name's Website", i"Welcome on $name's Website");

because interpolated strings are not strings. I would need an extra .text call.

I think as long as the call to default-interpolate to a string is somewhere at hand (like in object.d), then it's already a win.

My current problem with the status quo is not just that I have to reformat the string to have ugly printf style codes in it, but that I also have to now add an import somewhere.

>

I think it would be easier on users if it was all one big struct like InterpolatedString!(args here...) - not being able to be multiple arguments at once

Being a struct means it has to copy the data, which may not be desirable.

>

Otherwise if you had void foo(T...)(T args) you could no longer iterate over every argument individually, but need to keep track of state to know whether you are in an interpolated string. (and you don't know when it ends)

You do, because the first parameter tells you.

https://github.com/John-Colvin/YAIDIP#the-interpolation-header

-Steve

December 08, 2021
On Wednesday, 8 December 2021 at 13:28:33 UTC, Dennis wrote:
> On Wednesday, 8 December 2021 at 12:55:02 UTC, Adam D Ruppe wrote:
>> there's another good document mostly written but waiting on john and andrei to take the next step.........
>
> https://github.com/John-Colvin/YAIDIP

Does Dlang now support SQL injection?

Quotes from https://github.com/John-Colvin/YAIDIP:

```
void f2(string name) {
    htmlOutput("Looking for #{}...", name);                  // specifier is #{}
    auto rows = sql("SELECT * FROM t WHERE name = ?", name); // specifier is a question mark
    ...
}
````
This is an SQL query written lege artis. It enables the sql function to do whatever is necessary to perform the request without unwanted "side effects".

Further down we must read this:

```
void main(string[] args) {
    import std.stdio;
    writeln(i"The program $(args[0]) received $(args.length - 1) arguments.");
    // Lowering: --->
    // writeln(InterpolationHeader!("The program ", "args[0]", " received ", "args.length - 1", " arguments.")(),
    //     "The program ", args[0], " received ", args.length - 1, " arguments.");

    auto s = sqlExec(i"INSERT INTO runs VALUES ($(args[0]), $(args.length - 1))");
    // Lowering: --->
    // auto s = sqlExec(InterpolationHeader!("INSERT INTO runs VALUES(", "args[0]", ", ", "args.length - 1", ")")(),
    //    args[0], $(args.length - 1));
}
```

How is the proper separation of code (query) and data achieved in this case?

To me

   auto argsmaxidx = args.length - 1;
   auto s = sqlExec("INSERT INTO runs VALUES (?, ?)", args [0], argsmaxidx);

appears way more readable.
December 08, 2021

On 12/8/21 4:31 PM, kdevel wrote:

>

Further down we must read this:

void main(string[] args) {
     import std.stdio;
     writeln(i"The program $(args[0]) received $(args.length - 1) arguments.");
     // Lowering: --->
     // writeln(InterpolationHeader!("The program ", "args[0]", " received ", "args.length - 1", " arguments.")(),
     //     "The program ", args[0], " received ", args.length - 1, " arguments.");

     auto s = sqlExec(i"INSERT INTO runs VALUES ($(args[0]), $(args.length - 1))");
     // Lowering: --->
     // auto s = sqlExec(InterpolationHeader!("INSERT INTO runs VALUES(", "args[0]", ", ", "args.length - 1", ")")(),
     //    args[0], $(args.length - 1));
}

How is the proper separation of code (query) and data achieved in this case?

Because the sqlExec function figures it out based on the interpolation header. It can tell which parts were literal strings, and which parts were interpolation parameters. The interpolation parameters are replaced with "?", and then the parameters are passed as data (to avoid SQL injection as expected).

>

To me

   auto argsmaxidx = args.length - 1;
   auto s = sqlExec("INSERT INTO runs VALUES (?, ?)", args [0], argsmaxidx);

appears way more readable.

Both are readable, though I'd argue that for this particular example, the usage of $(expr) for syntax makes things complex to read (syntax highlighting should help). In our DIP we used ${expr}, which for SQL would be more readable, but might look worse for things like code mixins.

But there are plenty of examples where the string-blueprint form is less readable (the INSERT form where you specify fields first, and then parameters later is kind of a terrible syntax to begin with).

e.g. (from a real line of code in my codebase):

conn.exec("UPDATE organization SET loc_lat = ?, loc_lon = ? WHERE id = ?", loc_latitude, loc_longitude, id);

// compare to:
conn.exec(i"UPDATE organization SET loc_lat = $loc_latitude, loc_lon = $loc_longitude WHERE id = $id");

-Steve

« First   ‹ Prev
1 2 3 4 5 6 7 8 9