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

In the case they're describing this should almost surely not be a lambda function. Those should be reserved for when an arbitrary function makes sense, but it's unlikely that someone would have abstracted a function that could have done anything.

It's much more likely that the code in question is responsible for one particular thing, and switches between several different ways to achieve some sub-goal. Those parts should be lifted into some kind of interface, where the different variations are lifted into different implementations of that interface. A lambda function is the most general interface possible, so it's probably not the best choice, you'd eventually end up with callbacks calling each other without it being entirely clear which callback does what.



> A lambda function is the most general interface possible

A typed lambda function (i.e., with a defined arguments + return signature) is exactly as specific as any other typed interface, an arbitrary lambda function isn't, sure, but there's few languages where a static interface and an arbitrary lambda function are both available tools.


No, when each different way is unique to the caller, it needs to be defined at the caller.

This is what lambdas are for. Going to interfaces just adds needless syntax sugar.




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

Search: