Comment

Comment by WalterBright

I liked nested functions in Pascal, and put them in D. They turn out to be surprisingly useful:

1. Properly encapsulating their scope, as opposed to having static functions sit awkwardly somewhere else.

2. Factoring out common code within the function.

3. A lot of my need for goto statements vanished with nested functions.

4. Take the address of a nested function, and it serves as a lambda.

5. No need to create "Context" structs to pass local data to them.

6. They replace a lot of what C macros did.

7. They're inlineable, so are not costly.

I use them more and more as time goes by. It's a pity C doesn't have them, they'd fit nicely into the language.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton