[PYTHON] Discover the most yabe functions on github

Introduction

The other day, at work, I got excited with the story of "the most yabe function I repaired or wrote." Everyone talked a lot, but after all it was an overwhelming victory for the "command pattern main loop function (1500 lines)" I wrote. Why did you write such code?

So, today I will discover "the best function in the world" from github to heal my injured pride. In other words, "I'm going to see a Yabe function rather than a function I wrote."

Conclusion

Method

What is a yabe function?

Here, the Yabe function is identified by the following procedure.

  1. Identify "functions with high cyclomatic complexity". Cyclomatic complexity was calculated using lizard.
  2. Really narrow down to Yabe functions Look inside and exclude test code or auto-generated code.

Determining the target repository

Using github-trending-api, Look for Yabe functions by picking out popular projects from the last month in the following languages:

code

I don't do any tests cycro

result

1. Identify "functions with high cyclomatic complexity"

The top 10 functions with high complexity without considering the contents of the code are as follows.

No Complexity Function name Project name Language name
1 5505 jo node javascript
2 2013 matchIcon edex-ui javascript
3 2001 foo llvm-project cpp
4 1947 *global* node javascript
5 1868 cv::agast_cornerScore<AgastFeatureDetector::AGAST_7_12s> opencv cpp
6 1647 int kubernetes go
7 1532 foo llvm-project cpp
8 1509 OpenTag SuiteCRM php
9 1504 foo llvm-project cpp
10 1453 iT node javascript

2. Really narrow down to Yabe functions

If you actually look at the contents of the code ...

No Complexity Function name Project name Language name Remarks
1 5505 jo node javascript Because it is obfuscated
2 2013 matchIcon edex-ui javascript Just line up 2000 if statements
3 2001 foo llvm-project cpp For testing&&Just line up 2000
4 1947 *global* node javascript Because it is obfuscated
5 1868 cv::agast_cornerScore<AgastFeatureDetector::AGAST_7_12s> opencv cpp This guy is bad
6 1647 int kubernetes go Code automatically generated by the parser generator
7 1532 foo llvm-project cpp Test code
8 1509 OpenTag SuiteCRM php This guy is bad
9 1504 foo llvm-project cpp Test code
10 1453 iT node javascript Because it is obfuscated

Conclusion

As described in the remarks column, the following two are really yabe functions. See the actual code with your own eyes! (Too long to stretch)

No Complexity Function name Project name Language name Remarks
5 1868 cv::agast_cornerScore<AgastFeatureDetector::AGAST_7_12s> opencv cpp This guy is bad
8 1509 OpenTag SuiteCRM php This guy is bad

Comparison of complexity between languages

I plotted the complexity distribution for each language.

Violin plot with outliers

alt

Violin plot without outliers

Excluding values outside the range of mean ± 2 * standard deviation for each language, it is as follows. alt

Finally

Forgive me if I make a mistake ...

Recommended Posts

Discover the most yabe functions on github
Clone the github repository on jupyter notebook
Try CIing the pushed python code on GitHub.
Until the Sphinx documentation is published on GitHub
Probably the most unhelpful Python implementation method on Qiita
Notes on SciPy.linalg functions
Follow the mystery of orthographic-pedant that suddenly appeared on GitHub !!
Find the most F-word commit on Linux (git and later)