Petar Ivanov’s Post

4 attributes of scary code: 1. Feels needlessly complex. 2. Unclear intent. 3. No tests. 4. Buggy. 😬 This is a scary combo. It often means we're hesitant to touch it. Whoever does takes a big risk. Solution: 1. Create tests to cover the current working behavior. 2. Write a test that fails due to the buggy behavior. 3. Refactor to improve clarity, decomposing the code if necessary to improve the feedback loop and isolate the buggy section. 4. Make the test pass. How do you confront scary code in your projects? Drop your thoughts below! 👇 --- 👋 Join 28,000+ software engineers learning JavaScript, Software Design, and Architecture: https://thetshaped.dev/ ----- ♻ Repost to help others find it. #softwareengineering #programming #thetshapeddev

Another great one is workarounds to patch something that didn’t work as intended or wasn’t setup correctly. Great tip on creating unit tests. When sure what it does consult AI to understand and write tests so can conserve mental bandwidth for refactoring. Petar Ivanov

But sometimes you have to refactor the code to even make it possible to write tests in a practical way. I guess an iterative approach works for tests for untested code.

Like
Reply

Good tests turn scary code into safe ground. They protect what works and reveal what doesn’t. 

See more comments

To view or add a comment, sign in

Explore content categories