Extra Cheese

A Blog


Refactoring A Cyclomatic Complexity Script

Nov 16, 2009

I recently blogged about the cyclomatic complexity script I wrote that highlights Python code based on its complexity. The script itself is written in Python, but the code was rushed together. I decided to do some cleanup, recording the process as an example of refactoring.

You can see a lossless copy of the video by logging into Vimeo and clicking "Download Quicktime version" at the bottom right of the page. I recommend it; MPEG artifacting is no fun.

Refactoring A Cyclomatic Complexity Module from Gary Bernhardt on Vimeo.

I make one notable mistake – I leave an unneeded reference to "code_or_node" lying around. Just imagine that I delete it at the very end. :)



Showing 9 comments

Posted by Jonathan Penn at Mon Nov 16 12:19:56 2009

Thanks for sharing this, Gary.  You provide great insight into the refactoring process.  And you make the ruby programmers jealous, too. :-)

And you are also demonstrating the value of automated tests as the quickest possible REPL-like environment.  I hear ya when the tests take too long to run.


Posted by dgou at Mon Nov 16 22:27:16 2009

Nicely done! Thank you for taking the time to screencast it.


Posted by elephantum at Wed Nov 18 08:07:24 2009

your vim-fu is awesome, thank you


Posted by Amanda Laucher at Wed Dec 2 13:40:40 2009

Please do more of these and tweet about them. I love the idea of showing people how to think!


Posted by Griffin at Sun Dec 6 21:20:45 2009

I would love to know more about your vi setup if you wouldn't mind.


Posted by Griffin at Mon Dec 7 10:50:09 2009

I would love to know more about your vi setup if you wouldn't mind.


Posted by Jeff Gortatowsky at Tue Dec 8 11:50:54 2009

Excellent. Please do both: More like this AND the vim fu.


Posted by Godefroid Chapelle at Wed Dec 9 04:40:00 2009

Great example ! Thanks

Can you explain somewhere

1) which Python refactoring tool you use for Vim ?
2) how and which test runner is integrated into your Vim ?


Posted by Nasim at Wed Jan 6 13:35:44 2010

I really want to use vim. I want to know what setups are you using for your vim? Please share with us.

Thanks.


Name:


E-mail:


URL:


Comment: