Forward referencing functions in D

Steven Schveighoffer schveiguy at gmail.com
Fri Oct 16 21:28:18 UTC 2020


On 10/16/20 4:47 PM, wilcro wrote:

> 
> Thanks to all for your responses; as a related followup question, would 
> there be any reason to avoid placing the majority of code for a program 
> outside of the main function?

Inner functions have benefits:

1. They are only accessible inside the function. Which means you only 
have to worry about correctness while INSIDE that function.
2. inner functions have access to the outer function's stack frame.

Often, I use inner functions to factor out a common piece of code that I 
don't want to have to write multiple times in the same function.

-Steve


More information about the Digitalmars-d-learn mailing list