www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Article: The surprising thing you can do in the D programming language

reply aberba <karabutaworld gmail.com> writes:
Wrote something on OpenSource.com

https://opensource.com/article/20/8/nesting-d
Aug 20 2020
next sibling parent reply user1234 <user1234 12.de> writes:
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 ;)
Aug 20 2020
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
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.
Aug 20 2020
prev sibling next sibling parent Martin Tschierschke <mt smartdolphin.de> writes:
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!
Aug 20 2020
prev sibling next sibling parent reply MrSmith <mrsmith33 yandex.ru> writes:
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.
Aug 20 2020
parent aberba <karabutaworld gmail.com> writes:
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.
Aug 20 2020
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
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!
Aug 21 2020