Is there an alias for standard libraries to use in import statement?
Bastiaan Veelo
Bastiaan at Veelo.net
Sun Jul 4 16:11:54 UTC 2021
On Sunday, 4 July 2021 at 07:40:44 UTC, BoQsc wrote:
> I just started with a fresh look at the D language and would
> like to be able to rewrite this code:
>
>> import std;
>> void main()
>> {
>> writeln("Hello D");
>> }
>>
> Into more readable standard library name:
>>
>> import system;
>> void main()
>> {
>> writeln("Hello D");
>> }
That is [easy](https://run.dlang.io/is/af8dMY), just define the
`system` module and publicly `import std`:
--- test.d
```d
import system;
void main()
{
writeln("Hello D");
}
```
--- system.d
```d
module system;
public import std;
```
But like Mike, I advise against this. It will confuse every D
programmer that is trying to read your code. What is most natural
depends heavily on your background and what language you are
coming from. `std` is perfectly natural if you're coming from C++.
Fun fact (but equally ill advised): You can hide the entire
import from view like this:
```d
void main()
{
writeln("Hello D");
}
/* Lean on Enter for a while */
import std;
```
-- Bastiaan.
More information about the Digitalmars-d-learn
mailing list