views:

425

answers:

8

I work in a shop where the mentality/culture does not have any sense of the concept of "less being more" (i.e. the less code you have to maintain, the more flexible you can be, and the faster you can fulfill customer requests). There's also a strong copy-and-paste mentality around here.

The backend code base being used is written in rather verbose C++ (the code base is 1.5 GB), and I have inherited some Javascript/HTML/CSS code from one of these C++ programmers that I have been tasked with "cleaning it up". The code was written to quickly appease some customers and is therefore not production level code (dispite the fact that it is being used in production-level systems).

The code has alot of document.write statements contained in <script> tags scattered throughout the html documents. It is some very obtrusive Javascript.

It also contains many style attributes in the actual HTML code itself rather than in a logical place like a stylesheet.

Also nobody seems to know what the code actually does, it's not commented, and this is why I've been tasked with cleaning up the old code rather than just trying to re-write it into a smaller, faster, more maintainable code base.

May I please have some advice on how to drive home the concept that "your should code smarter and smaller, rather than code more"?

Update

I've just added another question related to this one and @Joel's Answer bellow.

+1  A: 

Hire good developers and get rid of the bad ones.

My experience shows it is next to impossible to explain people that they're doing it wrong. They will only mode when a major breakdown happens, not until that. They will only see your "initiatives" as extra costs but not as a good investment.

Developer Art
I'm not the boss. I'm an employee trying to convince my boss about what needs to be done.
leeand00
Also, I'm the youngest developer here. Everybody else has been on for at least 15 years.
leeand00
changing the developers doesn't automatically change legacy code. you need refactoring, developers and money
Elzo Valugi
+4  A: 

You should challenge your own assumptions. You state that

You should code smarter and smaller, rather than code more.

Why do you think that's true?

If you can answer this question, then you know how to explain it to someone else.

Bill the Lizard
@Bill I think that is true because the amount of time it takes to edit a large verbose piece of code is greater than or equal to the time it takes to write a smaller/smarter well written piece of code.The time that you actually save however will be after the smaller/smarter code is written. This seems to be the concept they can't wrap their minds around.
leeand00
@leeand00: This is a good start. You should be prepared by asking yourself what arguments (or excuses, depending on your point of view) they're going to make to defend their position. Make sure you have counter-arguments ready. The one you'll probably hear most often is that they're under a tight deadline to "just get something working."
Bill the Lizard
+12  A: 

Introduce the concept of 'Technical Debt'. Just throw the term around now and then, along with a line about being smarter about accepting it, and let them figure out what you mean by it.

The point here is that while the idea of a term like "Technical Debt" should be obvious, it's also purposefully vague. You don't want to find yourself explaining what it is to any of the other developers; they should already know.

The idea is to subtly encourage them to explore the issues on their own, because that's really what you need to happen. As much as I like (and voted for) @Bill's answer, you'll never "win" this debate. It's just not how human brains work; people, even and especially programmers, are surprsingingly illogical about such things.

Eventually it will become a mechanism you can use to push back against bad implementation ideas in a way the other developers will accept: "It seems like this approach is taking on a lot of Technical Debt. Are we prepared for that?"

Joel Coehoorn
Technical Debt is a really good term used by many people that has "seen the light" ^^ +1
anddoutoi
Let me see if I've got the definition of Technical Debt right:"Sometimes you have to work on an issue to fix it for the customer in a timely manner. But when you do this, you incur 'Technical Debt' because sometime later you're going to have to deal with what you sent to the customer when you open the issue again. If you don't 'pay off the technical debt' by making it into a maintainable piece of code that is good for future maintenance by other programmers, you've just added another day and a half to the issue next time you have to make a change to it."
leeand00
The concept of Technical Debt is what you are dealing with right now I suppose. They (the other devs) did some quick-n-dirty implementations and now the company pay off the debt by having you amortize it ^^ Just like if you needed money very fast you take a quick loan (sms loan or something) with a high interest. After a while you have time to look for loans with a better terms (and interest) and you pay off.
anddoutoi
Something like that. There are lots of way to incur technical debt; some of them are even legitimate. But the main idea here is that it's a purposefully vague concept, and therefore will cause the other developers to think about it and explore the issue on their own. This is hugely important because you'll never "win" a debate of the issue. Human brains just don't work like that.
Joel Coehoorn
Hmm... promoting some of those ideas up into my answer.
Joel Coehoorn
"It seems like this approach is taking on alot of Technical Debt. Are we prepared for that?"I like that language Joel. Sounds like it might help.
leeand00
I'd say with my boss's way of seeing all code as "maintainable" this is going to be a little more difficult...hmm...
leeand00
Sure, all code *is* maintainable. But, it's a question of the *ease* of maintaining it. You can maintain a hammer easily, since it is simple. But, if someone created a "better hammer" with many moving parts, the cost of maintenance would be much greater.
John Fisher
+3  A: 

Personally, I think the fact that you have been tasked with cleaning up that mess is enough of a message. Even more so when you can prove that the time (read: money) spent on cleaning up the bad code, is more than the time that would've been spent writing good code in the first place.

To most managers, money speaks the loudest. To fellow developers, well, the one sure way to drive home the message is to have them maintain their own code. If they don't have to maintain it, there's simply no way you'll ever get programmers to change their ugly coding practices.

Edit: As Piskvor (in the comments to this answer) stated, responsibility is they keyword I was looking for. If programmers aren't responsible for maintaining and/or extending the code they're writing, it'll be extremely hard, if not impossible, to get them to accept better coding practices.

Duroth
Amen to that. If, on the other hand, there's no responsibility for the code, you'll see situations as "oh well, I'll just proclaim it completed and someone else will fix 'the bugs'" ("the bugs" - read: "missing features"). Real™ horror story.
Piskvor
"If they don't have to maintain it, there's simply no way you'll ever get programmers to change their ugly coding practices." Excellent point. I ran into this issue over and over at my last job. To be fair, I was occasionally guilty of this myself, especially with impending deadlines.
ThisSuitIsBlackNot
@Piskvor, ThisSuitIsBlackNot - I think almost everyone has done this at one point. It's probably part of the Nature of Man© (and Woman, ofcourse). Also, Piskvor, I very much like your keyword Responsibility. Mind if I edit that in my answer?
Duroth
@Duroth Oh they maintain their own code, it's just that they're self-taught cpp coders. Well to be fair, the boss is, he's very hard nosed and seems to think that any piece of code is maintainable (as he stays here most of his waking hours including weekends).
leeand00
@leeand00: If nobody (including the boss) minds maintaining what sounds like some fairly hideous code, it might be difficult to convince them to change their ways. I think the best approach would be to show them the alternative. They might start to pay attention when they see you spending half as long maintaining a well-written piece of code than they are used to spending on their garbage code.
ThisSuitIsBlackNot
+1  A: 

The only way for your company to get out of this rut is to think that if there isn't enough time to do it correctly, then there isn't enough time to do it at all. Spend more time doing it correctly the first time. Push the deadline back. Your company is spending a lot of money maintaining old code, when you can be creating features for other products.

centr0
+2  A: 

There's an interesting article on this topic from Jason Fried of 37signals where he discusses this very concept (as well as other topics on running a successful business).

It's a good read.

http://37signals.com/svn/posts/1998-link-jason-fried-the-way-i-work

Robert Greiner
"Less is Less..." I'm liking this already! :)
leeand00
+1  A: 

Make them write unit tests for it. Insist on 100% (or even 95%) coverage. Insist all tests pass on check-in.

I find that, while coding is lots of fun, testing takes the fun out of it and really makes you think about whether you want to add that feature.

Alex Feinman
Alex you're really assuming that I have much more control over the situation that I do. And I disagree, unit testing makes coding more fun. Besides it's crazy to write code coverage for 100% of the code in your application (as it is just more to maintain), but there are instances where it helps when you're checking in and checking out code to make sure you haven't broken anyone else's code, and where it might help someone else (or even you) understand what the code was supposed to do in the first place.
leeand00
A: 

I know this type of situation. I've also had some daunting tasks which involved "cleaning up" other people's work. Some of those people weren't familiar with the environment and they wrote really ugly code.

My recommendation is the following: in the places where there is the most of the code smell, convince your boss and co-workers that it is so screwed up, that it actually takes LESS time to rewrite than to figure out how it works, what it does and how could it be fixed. After that, writing the new code should be straightforward, and then you can delete the obsolete code.

Venemo