paint-brush
Is Your Code Overly Complex?by@sourcerytim
473 reads
473 reads

Is Your Code Overly Complex?

by Sourcery17mMarch 11th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

We’ve all been there. Taking a look at a repo that we can’t quite make heads or tails of. Or looking at a function, reading through it, getting to the end, and then realising we’d need to read it five or six more times before we can grasp what it does. There are a handful of different ways to measure this area of code quality and to judge whether code is easily understandable, but today let’s focus, specifically on two measures of complexity – Cyclomatic Complexity & its younger sibling, Cognitive Complexity. What is Cyclomatic Complexity? The idea of Cyclomatic Complexity was first proposed in 1976 by Thomas McCabe as a way to figure out what software would be difficult to test or maintain. Cyclomatic Complexity can give a good proxy for how hard it is to understand code (more on this in a bit) and it can also help you determine the minimum number of tests you need to have complete test coverage over the section of code you’re looking at. To measure the Cyclomatic Complexity you can look at the control flow graph for a section of code to determine the number of independent paths for that source code.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail

Coin Mentioned

Mention Thumbnail
featured image - Is Your Code Overly Complex?
Sourcery HackerNoon profile picture
Sourcery

Sourcery

@sourcerytim

We help you make your Python code easier to read, understand, and work with through automatic refactoring suggestions!

Learn More
LEARN MORE ABOUT @SOURCERYTIM'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Sourcery HackerNoon profile picture
Sourcery@sourcerytim
We help you make your Python code easier to read, understand, and work with through automatic refactoring suggestions!

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Also published here
Buff
Buzzsumo
Ktachibana
Skrep
Coffee-web
Leftic
Allella
Poast
Trom
Censors