June 29, 2012 Re: foreach syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | > make -fwin32.mak release
That simple... :) Many thanks!
|
June 29, 2012 Re: foreach syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Friday, June 29, 2012 18:16:23 Namespace wrote:
> > It is redundant.
>
> But informative.
It's very common in D to not put the type unless it's absolutely necessary (e.g. use auto everywhere). This can be both good and bad for code readability and maintenance, but it's particularly useful with generic code, which is generally promoted quite heavily. So, I think that you'll find that most of the people around here generally don't explicitly use the type unless they need to (though there's always someone who's an exception).
- Jonathan M Davis
|
June 29, 2012 Re: foreach syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | But there is no overhead or something else _if_ i put the type, or? |
June 29, 2012 Re: foreach syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On 06/29/2012 09:51 PM, Namespace wrote:
> But there is no overhead or something else _if_ i put the type, or?
There is a slight typing and compilation overhead. Nothing significant.
|
June 29, 2012 Re: foreach syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Friday, June 29, 2012 21:51:20 Namespace wrote:
> But there is no overhead or something else _if_ i put the type, or?
No. It's like auto. The type is inferred. It's all statically typed and strongly typed. It's not like it figures out the type at runtime or anything like that. It's all done at compile time. It's just like C++11's auto. It makes refactoring code a lot easier, and it makes generic code a _lot_ easier to write. Without auto, std.algorithm would pretty much be impossible (you _could_ do it, but it would be so disgusting that no one would want to use it, because all of those compound range types get truly hideous if you actually look at the types themselves - voldemort types have reduced that problem, but they'd be impossible without auto anyway). It's up to you whether you want to put types explicitly or use let them be inferred with auto or in foreach loops, but it's more or less common practice at this point to use type inferrence very heavily and to avoid using types explicitly except when you need to.
- Jonathan M Davis
|
June 29, 2012 Re: foreach syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Friday, 29 June 2012 at 19:52:33 UTC, Timon Gehr wrote:
> On 06/29/2012 09:51 PM, Namespace wrote:
>> But there is no overhead or something else _if_ i put the type, or?
>
> There is a slight typing and compilation overhead. Nothing significant.
You missed a slight reading overhead.
|
June 29, 2012 Re: foreach syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Roman D. Boiko | On 06/29/2012 10:02 PM, Roman D. Boiko wrote:
> On Friday, 29 June 2012 at 19:52:33 UTC, Timon Gehr wrote:
>> On 06/29/2012 09:51 PM, Namespace wrote:
>>> But there is no overhead or something else _if_ i put the type, or?
>>
>> There is a slight typing and compilation overhead. Nothing significant.
>
> You missed a slight reading overhead.
Good catch.
|
Copyright © 1999-2021 by the D Language Foundation