Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've used nested functions more often than I'd like to admit, because dealing with insane callback-heavy APIs is made a lot easier with them.


I've never really thought to use nested functions for that. I guess I've never really thought of what nested functions were for.


Those of us who had nested functions/procedures and “procedural types” in Pascal (or Algol, but that’s beyond my experience) back in the day have :-)

Then K&R came, and took our nice toys away.

Fortunately, the GNU Pascal compiler needed nested subroutines, so they exposed the feature in their C compiler, as well.


And now even C# has them. :)

On C++ we can fake them with lambdas.


Welcome to the lambda party ;). Passing nested functions as pointers is how lambdas often work behind the scene.


I love using nested functions when I have to write state machine code. It's a hella a lot better than the old school way using macros to do the same thing.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: