3 ms·
So.... this is just a fancy name for the advice "give your functions a name"? The example he gave is just replacing an anonynous lambda for addition with a nam
by pierrebai 7y ago
So.... this is just a fancy name for the advice "give your functions a name"?
The example he gave is just replacing an anonynous lambda for addition with a named function call Add?
Maybe I'm too critical, but this is a thing I see in many fields:
1. Take a simple well-known idea and give it a new obscure name.
2. Write blogs, give lectures, organize summit and conventions.
3. Profit!
- barrucadu 7y agoAdd is a piece of data, not a function. The equivalent in C would be something like: enum function { add, ... }; // then inside your code switch(myfunction) { case add: return a + b; ... Defunctionalisation is about removing higher-order functions, not about naming anonymous functions. It's not a new trend, the first citation on wikipedia is to a paper in 1972.
- glouwbug 7y agoTwo problems I find: 1. You'll lose function inline optimizations, and also the branch predictor will get thrashed. 2. Local variables in that function essentially become globals.
- mmis1000 7y agoI think it depends on the compiler? In the example of that article, the only place that use the data structure is the when in the function that execute the data structure. A compiler may happily just inline it because no other where use it. And you lost no performance at all. Or it may just decide to generate the result as it and you surely have performance problem now.
- pierrebai 7y agoYou're focusing on my not knowing the syntax and specific of the languages. It's still just giving names to things that did not have a name. Whether the name is a variable name, a function name, a type name, doesn't matter. It's still a fancy, obscure jargonish way of saying "name things".
- dgb23 7y agoThere is naming but that is not the point. The point is that you turn functions into (serializable) data. Nothing fancy happening here.
- Smaug123 7y agoNo, that's not the point at all. We are not replacing an anonymous lambda with a named function call; rather, we are replacing an anonymous lambda with a specific (finite, inspectable, small) piece of data. Then, later on, we decide what to do with that small piece of data: often, we replace it with a genuine function call, but sometimes (e.g. in the "testability" section) we might just decide to inspect it instead.
- svat 7y ago> So.... this is just a fancy name for the advice "give your functions a name"? Not quite: "defunctionalization" is a name for replacing functions with not-functions (data structures). (And IMO it's the most unfancy name one can give to that activity, as the name literally just indicates "removing functions"... I can't think of a less fancy name for it: maybe "un-function-ize"? But that's pretty much the same as "defunctionalization".) BTW I recommend reading the 3 linked articles in this order: 1. https://blog.sigplan.org/2019/12/30/defunctionalization-everybody-does-it-nobody-talks-about-it/ https://blog.sigplan.org/2019/12/30/defunctionalization-ever... 2. http://www.pathsensitive.com/2019/07/the-best-refactoring-youve-never-heard.html http://www.pathsensitive.com/2019/07/the-best-refactoring-yo... (with accompanying video) 3. https://www.gresearch.co.uk/article/defunctionalisation/ https://www.gresearch.co.uk/article/defunctionalisation/ (this one actually shows how you can incrementally adopt this)