lizard icon indicating copy to clipboard operation
lizard copied to clipboard

Idea needed: Javascript anonymous functions

Open terryyin opened this issue 4 years ago • 1 comments

It seems anonymous functions are very common in javascript (so as short lambda in other languages).

I'm wondering if it makes sense to stop counting anonymous function complexity and simply add/merge it to the named function that's containing it.

const sum = array => array.reduce((a, b)=>a+b)

becomes one function named sum with CCN 1.

What do you think?

terryyin avatar Jul 10 '21 06:07 terryyin

Sorry for being so late (I stopped using lizard for a while and still struggle to make the tool not encounter recursion overflows when visiting specific huge source trees - cf. #293).

Yes, I am in favor of taking anonymity as a hint to not consider with a made up name but instead to accumulate the complexity in the parent scope.

In real life I sometimes see "could have been translation units" wrapped into a slick little anonymous function. Now in these not so rare cases, I wonder if adding a constant wun to the overall complexity of the surrounding scope is realistic?

sthagen avatar Oct 27 '21 09:10 sthagen