Hola a todos, esta no es una pregunta, sino que estoy publicando los descubrimientos en Dlang en mi github

Salih Dincer salihdb at hotmail.com
Thu Oct 17 04:56:36 UTC 2024


On Wednesday, 16 October 2024 at 23:54:45 UTC, Danico wrote:
>
> https://github.com/Alinarov/D-descubrimientos

¡Bienvenido (Bienvenida ?) a nuestro D Forum! Nos alegra mucho 
tenerte con nosotros. Es obvio que no estás empezando, y estamos 
seguros de que tu experiencia será de gran valor para todos. Pero 
es necesario escribir en inglés:

Welcome to the world of D. It's obvious you're not just starting 
out. You will definitely get better with time. When I look at 
your code snippets, the first lines usually start like this:

```d
#!/usr/bin/env dmd
import std;

alias print = writeln;

//...
```

I'm sure you chose the print alias for convenience. But you can 
do something similar much more easily. Here it is:

```d

import std.stdio : print = writeln;

```

This way selective importing makes it easier to learn the 
standard library and optimizes the compiled code in the best way 
possible. For example, the following function is very enjoyable 
to read:

```d
auto maxPow(ulong a, ulong b)
{
   import std.math : pow;
   import std.algorithm : min, max;
   auto power = a.min(b);

   return a.max(b).pow(power);
}

unittest
{
   assert(maxPow(2, 5) == 25);
   assert(maxPow(5, 2) == 25);
   assert(maxPow(5, 0) == 1);
   assert(maxPow(0, 5) == 1);
}
```

It may seem strange to you to use import lines inside functions, 
here, there, everywhere. But rest assured, this experience will 
provide you with advantages that are not available in almost any 
other programming language.

Of course, the choice is yours, it is possible to make everything 
much easier with `import std`. 😁

SDB at 89


More information about the Digitalmars-d-learn mailing list