4 ms·
It's not so much naming the function, but that doing so moves it outside the flow of the logic it is participating in. Especially when it's going to reference l
by zmmmmm 8y ago
It's not so much naming the function, but that doing so moves it outside the flow of the logic it is participating in. Especially when it's going to reference local context that is particularly confusing. There are definitely times when extracting out a function and naming it is the right thing to do. But there are an equal number of times when keeping all the local context together is better. It's probably hard to appreciate this unless you spend some time in languages where closures are seamlessly integrated like Groovy.
- mlthoughts2018 8y agoI find it tremendously helpful to move the function out of the flow of logic so it is modularized. When I read scala or haskell code where as soon as you see map or filter or something you know you’re gonna get some crazy anonymous function to follow, I get sad because it’s a miserable and confusing way to write code instead of pulling the function out into a separate definition with documentation, and then having the map or filter part be extremely concise using only predefined functions.
- jcelerier 8y ago> I get sad because it’s a miserable and confusing way to write code you just have to visualize it as a tree
- mlthoughts2018 8y agoYes, that is a confusing way to write and read code, rather than a linear flow, like flattening the tree by extracting functions into separate definitions.
- deleted 8y ago[deleted]
- jcelerier 8y ago> Yes, that is a confusing way to write and read code, rather than a linear flow, like flattening the tree by extracting functions into separate definitions. I don't understand. It's harder to flatten the tree: you have to unflatten it in your mind afterwards to understand what's happening. It's easier to just visualize, say, this lisp function as a tree directly. (defun good-enough-p (guess x) (format t "~% Guess =~7,4f Guess^2 = ~7,4f Error= ~7,4f" guess (* guess guess) (abs (- (* guess guess) x))) (< (abs (- (* guess guess) x)) .001))
- another-cuppa 8y agoI've used Lisp extensively and I've used closures extensively. In Python you can simply define the function on the line above where you plan to use it. I really don't see the need. Lisp needs lambda because you can't just randomly introduce new variables everywhere (you have to use flet, which actually is a lambda).