DEV Community

Discussion on: Not every function needs a name

Collapse
 
joeattardi profile image
Joe Attardi

I agree that arrow callback functions don't need names, if it is a simple function of just a few lines. If there is more complex logic I prefer to extract that into a named function and pass it as the callback, e.g.

arr.forEach(doSomeStuff);

But what drives me crazy is top-level anonymous arrow functions. I mean this:

const foo = () => {
   // ... some stuff here
}

I think functions like this should always have a name.

I understand Kyle's dislike of anonymous functions but I think he takes it a bit far.

Just my opinion.

Collapse
 
macsikora profile image
Pragmatic Maciej

Generally what you said is almost exactly what I tried to describe in the article. With this difference that I don't understand Kyle dislike for anonymous functions at all, his arguments like - if you have no clue how to name something, name it - todo, are for me just bizarre. And I am not joking, he is really proposing that in his book.

I vote here for commons sense, name things when it has sense to name them, and if you do, name them accurate. There is nothing worst then bad names.

Thanks for the comment!

Collapse
 
joeattardi profile image
Joe Attardi

I think one of the main criticisms is that they just show up as (anonymous) in a stack trace, so it might make debugging harder.

Honestly, that's the only issue I can think of.