3 ms·
If the function is large, sure, make it into it's own name thing (with as restricted a scope as you can get away with). However, many languages support callbac
by Roboprog 9y ago
If the function is large, sure, make it into it's own name thing (with as restricted a scope as you can get away with).
However, many languages support callbacks/lambdas/closures/blocks as parameters to generic library code, and these dangly bits are often one or two lines.
E.g. (pseudo-code) -
* list.for-each : print
* list.filter : is-wanted
* db-connection.bracket-transaction : compound-update
This allows you to use, or create your own, library code as extensions of the language to reduce boiler-plate code for visiting, filtering, resource management, etc.
Have a look at something like the Ruby language to see how this is exploited to reduce A LOT of code noise.
- Roboprog 9y agoSome might also argue that "private methods", which are visible to every other method in a class, are a bad thing, rather than making a nested function within the only function / method that used said code. One of the things I used to be able to do in Pascal, that C ... Java and their ilk took away. Fortunately, most FP languages gave that back, with interest (closures).
- int_19h 9y agoC# just got true nested functions back in 7.0. Although, as you have said, it is somewhat redundant with closures, and even more so with local type inference. C++, C# and Java all let you do what effectively amounts to a local function these days.