Discussion Thread: DIP 1036--String Interpolation Tuple Literals--Community Review Round 2

Arafel er.krali at gmail.com
Fri Jan 29 13:02:16 UTC 2021


On 29/1/21 12:14, Walter Bright wrote:
> On 1/29/2021 2:53 AM, Arafel wrote:
>> Of course one could settle on a default placeholder and then reparse 
>> the string to adapt it as needed, that's in fact what JDBC does, 
>> but... here we have the chance to do the right thing from the beginning.
> 
> I bet it could be done with a template overload of the function call. 
> This doesn't make it worse than DIP1036, which requires template 
> overloads written by the user anyway.

You seem to refer to the library author as the "user", for me the "user" 
is the actual user of the library, and I'd say this kind of user is much 
more important (if only because there are more of them). It is them who 
should have an easy time, even if it requires a bit more effort from the 
library author.

And I'm not sure how a template overload could possibly work with 
interfaces. The database driver often needs to be chosen at runtime, so 
you get something like this:

```
string dbDriver = readConfig("dbDriver");
auto connection = Driver.getDriver(dbDriver).getConnection(/* connection 
parameters * /);
auto result = connection.execute(i"select * from foo where id = 
${obj.id} and val > ${minval}"); // Needn't care about the internals
```

That's how it should look like for the end user.

I don't see how the syntax of your example of DIP1027 could be easier 
than this for the real end-user... and not even for the author of the 
library.

Just for completion, this is how the SQL library might look like 
(shameless copy of the structure of JDBC):

```
class Driver {
	static public Driver getDriver(string name) { /* ... */ }
	static public void register(Driver driver, string name) { /* ... */ } 
// To be called by each driver in `shared static this`
	abstract public Connection getConnection( /* ... */ );
}
interface Connection {
     // ...
     public Result execute(/* ... */);
}
interface Result { /* ... */ }

class MySQLConnection : Connection {
     // ...
     override public Result execute(/* ... */) {
         /* uses msql_query(...) and `?` */
     }
}

class PostgreSQLConnection : Connection {
     // ...
     override public Result execute(/* ... */) {
         /* uses postgres_query(...) and `$1`, `$2`, etc. */
     }
}
```


More information about the Digitalmars-d mailing list