News for hackers. Stuff that matters.
Re:Please do not attempt to simplify this code by m_mueller on Friday December 28, 2018 @03:27AM (#18775522)
Totally agree on nested functions. I currently have to deal with Java, and those are the biggest thing I miss from Python.
Re:Please do not attempt to simplify this code by cmsj on Friday December 28, 2018 @06:46AM (#18776230)
I would make no claims to being an exceptional programmer, but fwiw I don't like nested functions - it always takes me a lot longer to reason about what a function is doing, when it has functions defined inside it.
Re:Please do not attempt to simplify this code by barrkel on Friday December 28, 2018 @08:22AM (#18776547)
This can depend on the syntax and semantics of nested functions.

Pascal nested procedures are pretty easy to parse and if they're defined before the `var` block then you don't need to worry about non-local state modification (apart from the parameters, but modifying parameters is unusual).

First-class nested functions with variable capture are harder to understand. Nested functions in e.g. JS are more like object construction than function definition, and it's generally expected that such nested functions will be capturing state from the enclosing context.

Standard Pascal permitted outer scope variable access combined with downward funargs - the nested functions could be passed to other functions, but could not be stored in variables or returned as arguments. This reduces the non-local effects, and handily doesn't require a GC to ensure memory safety, since the captured state can stay on the stack, because the nested function won't outlive the frame.

For nested decomposition of a problem, I'm more of a fan of Pascal-style nested procedures than nested function expressions like in JS. Idiomatically, one expects function expressions to capture state, while nested procedures are just more procedural decomposition.

Re:Please do not attempt to simplify this code by m_mueller on Friday December 28, 2018 @08:54AM (#18776689)
I second the answer about having them before var-block: In python I always follow the style of having nested functions directly after the outer function header, and only going one layer deep. This way the only thing in their scope is their parameters as well as the parameters of the outer function. Using this restriction I find them very useful and concise - much better than having one-off helper functions in the outer module scope.
Re:Please do not attempt to simplify this code by sorokod on Friday December 28, 2018 @07:52AM (#18776449)
Kotlin supports nested functions along with quite smooth Java interop.