by somat · 2y ago · 0 comments
Classically trained math focused types tend to be especially bad at naming things. Which, I guess, is fine when developing the infernal equation. but it sure does not do anyone any favors when they have to understand the thing.
personally, in python, I refuse to use lambda functions on ethical grounds, all my functions are named. And then you should see my javascript, all those names would probably make any real JS dev sick.
Because in many cases a function is tightly associated with a particular context, and making it a separate named function is actually harmful for understanding.
personally, in python, I refuse to use lambda functions on ethical grounds
Do you really find this:
def get_name(x):
return x.name
sorted_by_name = sorted(people, key=get_name)
more readable than: sorted_by_name = sorted(people, key=lambda x: x.name) sorted_by_name = people.sort { it.name }Also due to the multiple style choices and options in JavaScript the readability is trash.
This is embarrassingly more literal than I would like, but I in large part refuse to use Python on something similar to "ethical" grounds because it doesn't support inline / multiline functions (and a couple of other similar issues).
After using typescript/ruby/groovy/scala/kotlin it's just so fused into my way of thinking about programming that each time I have to pull out an incidental function from its context and it reduces the clarity of the code, I grind my teeth. I'm guessing you just won't understand this unless you immerse yourself in another language and its idioms.
Anonymous functions are amazing for: * Iterators (map, reduce, filter) * Callbacks (ui actions) * Threads/async tasks
The reason I don't name them isn't because I can't think of a name, it's because: * There's no point, they'll only be referred to once * Introducing a separate function block breaks the flow of the code and makes it harder to read (especially for iterators!)