On Monday, 21 June 2021 at 13:23:04 UTC, Steven Schveighoffer wrote:

For sure there is a difference in what the compiler has to do.

Indeed.

But I think the check is likely trivial, and inconsequential as far as compiler runtimes. D is going to already figure out the types of expressions *with or without explicit types*. The extra step is when it has to check if it can convert from the detected type to the declared one.

Indeed to. I think that when I asked for advice I was not thinking very much on compile times but far more on adding unneeded complexity or, far worse, shooting me in the foot due to sheer ignorance, so, better ask beforehand.

I would be more concerned with possible conversions you didn't expect being silently performed by the compiler. e.g. if a type is alias this'd to a `string`, and you declare `string` as the foreach type, then it's going to run the alias this at runtime, even if that might be expensive.

On this I am fully-covered since I always convert with cast() even for stupid cases like:

```d
long intWhatever = 0L;
```

I never, ever, get compilation warnings or bugs for this type of stuff :) It is hard-wired on me.

This might happen even though you wrote the actual type at the time -- sometimes library code changes the type, and just uses alias this to allow original code to compile.

For what I was reading a couple of days ago while navigating the general forum, alias is something very useful that should be handled with care.

-Steve


Reply via email to