Thread overview
Article: The surprising thing you can do in the D programming language
Aug 20, 2020
aberba
Aug 20, 2020
user1234
Aug 20, 2020
H. S. Teoh
Aug 20, 2020
MrSmith
Aug 20, 2020
aberba
Aug 21, 2020
Walter Bright
August 20, 2020
Wrote something on OpenSource.com

https://opensource.com/article/20/8/nesting-d
August 20, 2020
On Thursday, 20 August 2020 at 10:12:22 UTC, aberba wrote:
> Wrote something on OpenSource.com
>
> https://opensource.com/article/20/8/nesting-d

I'm not sure. A few notes on nesting.

1. context pointer can prevent inlining. you can nest static funcs, but then what is the point
2. bad complexity. you can make the nested funcs static and factor them out. The code is more readable.
3. lambda. If you want to nest lambda are better. Solves point 2 but not point 1.

But otherwie still nice to see a bit of D promotion here and there ;)
August 20, 2020
On Thursday, 20 August 2020 at 10:12:22 UTC, aberba wrote:
> Wrote something on OpenSource.com
>
> https://opensource.com/article/20/8/nesting-d

Nice article! +1 up-vote!
August 20, 2020
On Thursday, 20 August 2020 at 10:12:22 UTC, aberba wrote:
> Wrote something on OpenSource.com
>
> https://opensource.com/article/20/8/nesting-d

The only nitpick, is that nested functions need to be declared before use, in order to compile.
August 20, 2020
On Thu, Aug 20, 2020 at 10:20:59AM +0000, user1234 via Digitalmars-d-announce wrote:
> On Thursday, 20 August 2020 at 10:12:22 UTC, aberba wrote:
> > Wrote something on OpenSource.com
> > 
> > https://opensource.com/article/20/8/nesting-d
> 
> I'm not sure. A few notes on nesting.
> 
> 1. context pointer can prevent inlining. you can nest static funcs, but then what is the point

The point is not to pollute module namespace with implementation details that are only relevant to that one function.

Also, if you're worried about inlining, use LDC instead of DMD. LDC is well able to inline nested functions.  Don't make judgments based on the DMD backend; it's well-known that its optimizer is ... sub-optimal...


> 2. bad complexity. you can make the nested funcs static and factor them out.  The code is more readable.
[...]

The point is not to pollute module namespace with functions that are only relevant as implementation details of one function.


T

-- 
First Rule of History: History doesn't repeat itself -- historians merely repeat each other.
August 20, 2020
On Thursday, 20 August 2020 at 11:22:53 UTC, MrSmith wrote:
> On Thursday, 20 August 2020 at 10:12:22 UTC, aberba wrote:
>> Wrote something on OpenSource.com
>>
>> https://opensource.com/article/20/8/nesting-d
>
> The only nitpick, is that nested functions need to be declared before use, in order to compile.

You're right. Missed that. Copy-pasting and using D and JavaScript at the same time.

I've notified that editors, it'll hopefully be corrected soon.
August 21, 2020
On 8/20/2020 3:12 AM, aberba wrote:
> Wrote something on OpenSource.com
> 
> https://opensource.com/article/20/8/nesting-d

Very nice! Thank you, Lawrence!