3 ms·
I am not a fan of anonymous functions. I think they are evocative of maths culture tendency to remove and make meaningless names(for example, using greek letter
by somat 4y ago
I am not a fan of anonymous functions. I think they are evocative of maths culture tendency to remove and make meaningless names(for example, using greek letters). Yes I know naming things is hard, but names are important, they are critical labels about the inner inner working of the machine.
Nothing wrong with functional programing, in fact it is pretty great, But I wish people would name their functions.
- deleted 4y ago[deleted]
- bradrn 4y agoOn the other hand, sometimes it’s better to avoid naming functions, especially if they’re small and only used once. For instance, if I’m doing something like ‘map (\(x,y) -> (x,y+1))’ to increment the second element of each item in a list (using Haskell syntax), naming the anonymous function won’t necessarily make anything clearer. Or consider this example from my own code: zipWith (\i m -> fmap (i,) m) [0..] Sure, I could rewrite it as ‘zipWith prependToEachElement [0..]’, but if you know Haskell that’s not all that much shorter or clearer, especially for a function which might only be used once in the whole program.
- skybrian 4y agoThis assumes you're writing generic, mathematical code. Maybe that's common in Haskell, and I agree that there often aren't helpful names in that situation. But usually, if you're working with a list, it's a list of something specific, and the names should reflect that. If we're doing graphics and those (x,y) points are interpreted as points on a graph, then it's really: moveUpOne = (x,y) => (x,y + 1) map(moveUpOne, points) Or maybe it's moveDownOne? Depends on your coordinate system. Similarly, you're probably prepending to a list for some application-specific reason. The code should use application-specific jargon.
- antonvs 4y agoIn Haskell you can implement moveUpOne as: moveUpOne = fmap (+1) ...which uses a map over a functor, in this case a tuple. But once you're familiar with functors, there's not that much benefit in naming something like that, much as you wouldn't typically define `add1 = (+1)`.
- skybrian 4y agoThat's significantly less readable since you can't see that you're working with ordered pairs that have x and y coordinates. Don't hide the data structure.
- avindroth 4y agoI think it's a balancing act between labeling and mislabeling. Some things are so hard to name that naming them actually hurts. Also sometimes you don't want to pin down what it actually is; naming restricts the concept. Wrt maths, you did maths without greek letters and with plain english, you'd have pretty ugly formulas. Greek letters, while obtrusive to newcomers, can be a lifesaver for conciseness in expression.
- tpoacher 4y agoin the right context, greek letters were actually supposed to represent meaningful names. especially with Greek historically treated as the lingua franca for science. the fact that most people abuse greek letters for this purpose says more about most people than about the utility of greek letters in formulae. (but otherwise, yes, I agree with the more general point)
- elzr 4y agoHave you checked the interface that Google Sheets came up for custom functions? It's in the menu of every spreadsheet in Data > Named Functions. It's pretty good and encourages not only extensive naming but documentation & examples of the function and each argument. These descriptions are then displayed piece-meal as you edit a formula, just like native documentation. I also love good names! I hated not being able to have names in formulas and the name part of Named Functions is alone a big quality of live improvement for me. As to lambdas, perhaps calling them anonymous functions is giving the wrong impression here. What lambdas really are is a simple, native way to create a context with local names. They can be a great boon to clarity through naming! Spreadsheets have been historically so limited that programmers have resorted to hacky ways to have names/comments. The N function for numerical values is used sometimes for this since N of a string defaults to 0: so N("Name/comment") = 0 and can be added to a formula without changing it. As to the cultural practice of ultra-short, likely meaningless variable names, like single letters. I do agree it's a "mathy" thing and can quickly descend into maddening opaqueness. The trick though is that sometimes it's very useful to have as compact a symbolic representation as you can manage (such a process of abbreviation gave us algebra!). Naming things is hard, perhaps one of the truly hard things in thinking/programming as the saying goes :)