D is our last hope
Walter Bright
newshound2 at digitalmars.com
Wed Dec 20 00:49:44 UTC 2023
On 12/19/2023 1:52 PM, Adam D Ruppe wrote:
> I still say the best thing to do is to ditch the overloading of the `import`
> keyword and instead embrace the `mixin` keyword.
>
> mixin[C](`#include<stdio.h>`);
>
> you can now use the full file name, with .h or .c or whatever you want. And you
> can do this in context of D, meaning you can do things like :
>
> @nogc {
> mixin[C](`#include<stdio.h>`);
> }
>
>
> And potentially use macros:
>
> enum C_Context = mixin[C](`#define foo bar`);
> mixin[C, C_Context](`use foo here`);
>
> or something like that.
Programming with multiple languages is complicated, and it can work if the
import mechanism gets to say what language the imported file is in.
I really like making things as simple as possible, and having them "just work".
It's hard to beat:
import whatever;
and not having file.d, file.c, and file.h in the same directory. Then life gets
a lot simpler. After all, D was designed with the notion of package.module
mapping directly onto directory/file. That inevitably results with some
compromises on the names of the directories and files, etc., but it is worth it
for the vast simplification of a 1:1 mapping.
More information about the Digitalmars-d
mailing list