Question

I've been programming for a few years, and have become very familiar with C# and JavaScript over time. I have some larger C# and JavaScript projects that I have no trouble navigating around. I recently started a PHP & AngularJS project for work with no prior experience with PHP.

The flow of the PHP side of things is becoming hard to keep track of (The JavaScript side is larger, but easy to work through), when I try and think through it I imagine a tangled ball of thread. Major design mistakes that I made when I started are beginning to pile up and effect my design going forward. It takes longer and longer to implement anything new.

I'm on a tight deadline and finding it harder and harder to write good, DRY, SOLID, code. It's becoming more enticing to copy/paste chunks of code to make slight variations to it's behavior as design time goes up. It's also taking a long time to get back into the code base whenever I have to do a context switch (From one project then back to this one), I have a feeling of dread whenever I go back to work on this project.

What steps can I take to remedy this? The extra time it might take needs to be justifiable as well, my boss is not a developer and is not familiar with development or software life cycles so explaining might be more difficult than normal.

Was it helpful?

Solution

You are taking on technical debt. The more you justify sloppy code with deadlines the more deadlines will see you achieving less and less.

Understand that you can completely get away with this. No ones going to catch you making a mess and ball you out. You're just going wake up one day surrounded with clutter.

At that point you'll either update your resume and make it my problem or you'll decide to pay down the debt and spend some time cleaning the code.

If you go the cleaning rout understand this isn't about "spending more time on design". This is about breaking some lazy habits and taking out the trash.

Throwing out dirty code wholesale is a bad idea. Not because of the work that went into it, but because working code captures an idea. Move the idea into clean code before you trash the dirty code.

Having unit tests helps with this but if you created your tests with the same care you put into the mess they likely need fixing as well.

Don't give into rigidity. If you can't change it then it's not software.

OTHER TIPS

It takes longer and longer to implement anything new.

This is your justification. 'fess up, eat some crow, and explain why things are taking longer and that you need to spend a little time refactoring + redesigning the system.

If you don't do that, you'll need to refactor little by little, on the down-low. Tasks are already taking longer than you want them to - take a little extra time every time you touch the code base to try and make something better. Add an integration test. Extract an abstraction.

The stupid answer to "How do I refactor a huge project?" is, "One piece at a time".

EDIT

Was reading related posts, and came across this blog post: http://ronjeffries.com/xprog/articles/refactoring-not-on-the-backlog/. TLDR: don't attempt to create a huge refactor 'phase' in your project; it's unlikely to get buy-in from the project owners, and you'll be unguided in your choices about what to tackle during the time you have. Instead, take the time for each new change or bugfix to weedwack the code that you are working with right now. Don't allow smells to stick around when you have an opportunity to fix them.

Sonarqube supports PHP so you can help track your current debt and new leaks. http://docs.sonarqube.org/display/PLUG/PHP+Plugin

Live sample with Drupal https://sonarqube.com/dashboard?id=drupal

Licensed under: CC-BY-SA with attribution
scroll top