14

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.

  • 4
    Possible duplicate of How can I convince management to deal with technical debt? – gnat Nov 15 '16 at 19:37
  • 1
    Thanks @gnat However, I'm less interested in making a case for my boss than I am figuring out how to actually fix the issues themselves. Making a case to my boss will do no good if I don't know a good methodical way to identify and change issues. – Douglas Gaskell Nov 15 '16 at 23:10
11

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.

  • 1
    "No ones going to catch you making a mess and ball you out." ...Unless you do code review. ;) – jpmc26 Nov 16 '16 at 0:01
  • 1
    @jpmc26 If you think code reviews will save you from this fate you're mistaken. Code reviews only help you when you're willing to learn from others. Not when you focus on a deadline. Working, messy, code will trump opinions again and again. I've seen managers resolve these disputes by flipping a quarter. If you don't care about quality no one will be able to drag it out of you. Do not think you can rely on others to keep you from making a mess. If it comes to that, they'll just assign you to update documentation. – candied_orange Nov 16 '16 at 0:54
  • If you read my comment and thought that I was saying code reviews are magic like unicorns and rainbows that will fix everything without any effort or willingness, you're incredibly mistaken. But they do give someone the chance to call you out on it. – jpmc26 Nov 16 '16 at 3:17
  • 1
    @jpmc26 If you read my answer and thought that I was saying there is no hope just give up, you're incredibly mistaken. I'm calling on programmers to take personal responsibility for clean code rather than relying on any process to make it happen. Only one thing maters. You either care or you don't. – candied_orange Nov 16 '16 at 3:20
  • Of course, but even the best programmer will make dumb decisions every now and then. Code reviews with another person give you the chance to put your code in front of someone else who can catch them earlier. That's the whole point. It's hard to see problem spots by yourself until you actually try to change something and it becomes difficult. Of course code reviews and any other technique are useless if you don't care. – jpmc26 Nov 16 '16 at 3:31
9

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.

  • 3
    That's exactly what I did with my heritages in the past. The nice thing: once you got the turning point, the project starts glowing like with fairy dust. – qwerty_so Nov 15 '16 at 22:00
-2

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

  • 1
    Sadly I cannot install JVM on my work device. This looks like a great tool otherwise. – Douglas Gaskell Nov 15 '16 at 23:21
  • That's pretty draconian for a developer workstation. – Archimedes Trajano Nov 15 '16 at 23:24
  • I don't have local admin, or any install permissions, or run permissions for any non-white listed applications. It used to be much worse.... sadly. – Douglas Gaskell Nov 15 '16 at 23:31
  • Can't say I empathize, I do sympathize though. – Archimedes Trajano Nov 15 '16 at 23:33
  • downvoted as it's just an advert/link to a tool, not an answer to the OP's question. – James Snell Nov 15 '16 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.