<p>You've just written a pile of code to deliver some important feature under pressure.  You've cut a few corners, you've mashed some code into some over-bloated classes with names like SerialIndirectionShutoffManager..</p>

<p>You tell your boss you're going to need a week to clean this stuff up.</p>

<p>"Clean what up?"</p>

<p>"My code - its a pigsty!"</p>

<p>"You mean there's some more bug fixing?"</p>

<p>"Not really, its more like.."</p>

<p>"You're gonna make it run faster?"</p>

<p>"Perhaps, buts thats not.."</p>

<p>"Then you should have written it properly when you had the chance.  Now I'm glad you're here, yeah, I'm gonna have to go ahead and ask you to come in this weekend.. "</p>

<p>I've read Matin Fowler's book, but I'm not sure I agree with his advice on this matter:</p>

<ul>
<li>Encourage regular code reviews, so refactoring work is encouraged as a natural part of the development process.  </li>
<li>Just don't tell, you're the developer and its part of your duty. </li>
</ul>

<p>Both these methods squirm out of the need to communicate with your manager.</p>

<p>What do you tell your boss?</p>

[{'answer_id': 77206, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 3, 'selected': False, 'text': "<p>Lie. Tell him it's research into a new technology. Then tell him you decided the cost didn't justify the benefits. He'll think you did a great job.</p>\n\n<p>lol @ people down modding / marking offensive.</p>\n\n<p>Really, if it's a penny pinching boss, who doesn't understand good software from cheap software, what he doesn't know will ultimately make him happier. if it was me, i would leave the company and go someplace where they respect their developers ability to write good code. But then again, this is why I'm in a senior position.</p>\n"}, {'answer_id': 77230, 'author': 'Keith Nicholas', 'author_id': 10431, 'author_profile': 'https://Stackoverflow.com/users/10431', 'pm_score': 2, 'selected': False, 'text': '<p>Refactoring you should do all the time.... so you shouldn\'t have to justify it.</p>\n\n<p>Cleaning up big messes / Redesign  may include refactoring in order to get it under control, however its not "Refactoring"</p>\n\n<p>Refactoring should be a matter of moments...or if you have no tool support, minutes.</p>\n'}, {'answer_id': 77236, 'author': 'Alex B', 'author_id': 6180, 'author_profile': 'https://Stackoverflow.com/users/6180', 'pm_score': 2, 'selected': False, 'text': '<p>I like the answer given in "Refactoring" by Martin Fowler.   Tell your boss that you are going to develop software the fastest way that you know how.   It happens that in most cases the fastest way to develop software is to refactor as you go.</p>\n\n<p>The other thing to tell your boss is you are reducing the cost to make future improvements.</p>\n'}, {'answer_id': 77240, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Tell him 80% of the costs associated with a software project comes in the maintenance phase of the lifecycle. Any refactoring done now to alleviate future problems, and have some examples, will net substantial cost benefits later on when the need arises to maintaining that code.</p>\n\n<p>This is assuming you are refactoring for a reason and not for programmer vanity.</p>\n'}, {'answer_id': 77241, 'author': 'John Flinchbaugh', 'author_id': 12591, 'author_profile': 'https://Stackoverflow.com/users/12591', 'pm_score': 3, 'selected': False, 'text': "<p>Just do it and schedule it into your normal process.  Estimate refactoring time into starting a new change or into finishing a change (ideal).\nI always refactor while I'm initially exploring new code (extracting methods, etc).</p>\n"}, {'answer_id': 77242, 'author': 'Brian Leahy', 'author_id': 580, 'author_profile': 'https://Stackoverflow.com/users/580', 'pm_score': 5, 'selected': False, 'text': '<p>Speak in a language he can understand.</p>\n\n<p>Refactoring is paying design debt.  </p>\n\n<p>Ask your boss why he pays the company credit card bill every month vs not paying it until there is a collections notice.  Tell him refactoring is like making your monthly payment.</p>\n'}, {'answer_id': 77247, 'author': 'japollock', 'author_id': 1210318, 'author_profile': 'https://Stackoverflow.com/users/1210318', 'pm_score': 0, 'selected': False, 'text': '<p>Less money now for me to refactor...</p>\n\n<p>or more money later to fix whatever goes wrong and for me to refactor.</p>\n'}, {'answer_id': 77261, 'author': 'Torlack', 'author_id': 5243, 'author_profile': 'https://Stackoverflow.com/users/5243', 'pm_score': 2, 'selected': False, 'text': "<p>In one of Robert Glass's recent books (I'll have to look up the reference) he mentioned a study on the cost of well maintained code.  What they found is that well maintained code was edited more often than poorly maintained code.  That sounds counter intuitive but when they dug deeper the discovered the reason:</p>\n\n<p>Well maintained code has more features added to it in the same time frame than poorly maintained code.</p>\n\n<p>Does your Boss like features?  Sure, they all do.  If more you improve the maintainability of the code, the more features you will be able to deliver with that limited budget.</p>\n"}, {'answer_id': 77363, 'author': 'Charles Graham', 'author_id': 7705, 'author_profile': 'https://Stackoverflow.com/users/7705', 'pm_score': 0, 'selected': False, 'text': '<p>Sometimes, it\'s just time to get a new job.  There are certian poeple who just want you to "get it done".  If you are ever in one of those situations, and I\'ve been there, then just leave.</p>\n\n<p>But yeah, all that other stuff about future costs and such is  good idea.  I just think that most bosses lie to themselves because they want what they want when they want it, and they are just not able to see what\'s going to happen in the future.</p>\n\n<p>So, good luck with your boss.  Hpefully he or she is reasonable.</p>\n'}, {'answer_id': 77425, 'author': 'Thomas Wagner', 'author_id': 13997, 'author_profile': 'https://Stackoverflow.com/users/13997', 'pm_score': 0, 'selected': False, 'text': '<p>Dont.... just go get a new job in a place thats more in synch with you. </p>\n'}, {'answer_id': 77459, 'author': 'Seibar', 'author_id': 357, 'author_profile': 'https://Stackoverflow.com/users/357', 'pm_score': 0, 'selected': False, 'text': "<p>I think you should just start working on it without telling your boss. This is truly how I've done my best work. I just don't tell my boss what I'm doing and slowly replace bad/legacy code when I have time. </p>\n\n<p>It has acutally saved my ass on more than one occasion.</p>\n"}, {'answer_id': 77526, 'author': 'nsayer', 'author_id': 13757, 'author_profile': 'https://Stackoverflow.com/users/13757', 'pm_score': 0, 'selected': False, 'text': "<p>If your boss doesn't understand the need to refactor or clean up code, then you have to wonder if he has enough engineering knowledge to be an engineering manager.</p>\n"}, {'answer_id': 77641, 'author': 'Orion Adrian', 'author_id': 7756, 'author_profile': 'https://Stackoverflow.com/users/7756', 'pm_score': 6, 'selected': True, 'text': "<p>It's important to include refactoring time in your original estimates. Going to your boss after you've delivered the product and then telling him that you're not actually done is lying about being done. You didn't actually make the deliverable deadline. It's like a surgeon doing surgery and then not making sure he put everything back the way it was supposed to be.</p>\n\n<p>It is important to include all the parts of development (e.g. refactoring, usability research, testing, QA, revisions) in your original schedules. Ultimately this isn't so much a management problem as a programmer problem.</p>\n\n<p>If, however, you've inherited a mess then you will have to explain to the boss that the last set of programmers in a rush to get the project out the door cut corners and that it's been limping along. You can band-aid the problem for awhile (as they likely did), but each band-aid just delays the problem and ultimately makes the problem that much more expensive to fix.</p>\n\n<p>Be honest with your boss and understand that a project isn't done until it's done.</p>\n"}, {'answer_id': 77668, 'author': 'EvilEddie', 'author_id': 12986, 'author_profile': 'https://Stackoverflow.com/users/12986', 'pm_score': 0, 'selected': False, 'text': "<p>It's rare to find a boss who will give you time to refactor...just do it as you go along.</p>\n"}, {'answer_id': 77737, 'author': 'torial', 'author_id': 13990, 'author_profile': 'https://Stackoverflow.com/users/13990', 'pm_score': 0, 'selected': False, 'text': "<p>In my opinion, the simplest case to make for refactoring is fixing overly complex code.  Measure the McCabe cyclomatic complexity of the source code in question (Source Monitor is an excellent tool for such a problem).  Source code with high cyclomatic complexity has a strong correlation defects and bad fixes.  What this means in simple terms is that complex code is harder to fix and more likely to have bad fixes.  What this means to a manager is that the quality of the product will likely be worse, and the bugs harder to fix, and the schedule for the project ultimately worse.  However, in refactoring out the complexity, you are improving the transparency of the code, reducing the likelihood of obscure / difficult bugs, and making it easier to maintain (e.g. a maintenance programmer can have a larger maintenance scope because of this).</p>\n\n<p>Additionally, you can make the case (if it isn't a dead product in maintenance cycle) that decreasing complexity makes the application easier to extend when new requirements are added to the project.</p>\n"}, {'answer_id': 77814, 'author': 'Amy B', 'author_id': 8155, 'author_profile': 'https://Stackoverflow.com/users/8155', 'pm_score': 0, 'selected': False, 'text': '<p>The boss has to trust the dev to make correct technical decisions (including when to refactor).</p>\n\n<p>Establish that trust or replace the boss or replace the dev.</p>\n'}, {'answer_id': 6917850, 'author': 'Tom W', 'author_id': 313414, 'author_profile': 'https://Stackoverflow.com/users/313414', 'pm_score': 0, 'selected': False, 'text': '<p>Another good analogy is the maintenance of a tidy building site. The only catch here is that a programmer does not represent a construction worker, and a manager does not represent a foreman. If that were the case, his counter of "do it right first time" would still apply, since a competent and conscientious construction worker is responsible for maintaining good order on their workspace as they go. </p>\n\n<p>Really the <strong>code itself</strong> represents the labourers, and the development process is the foreman. The mess is generated by various trades going about their business around one another (i.e. by different code features interacting, where each feature does its job well, but the seams between them are disorganised) and is cleaned up by the foreman taking a firm hand and keeping an eye on where disorder is setting in, and acting to get it cleaned up (i.e. the software process demanding refactoring). </p>\n'}, {'answer_id': 11564382, 'author': 'clopez', 'author_id': 845225, 'author_profile': 'https://Stackoverflow.com/users/845225', 'pm_score': 0, 'selected': False, 'text': "<p>What I just did recently is to explain to my business counterpart that the re-factory process helps to develop new features faster and decrease the probability of new bugs because the code has a better order and structure, and is even posible to make some speeds improvements because you can inspect the code easier than before.</p>\n\n<p>When the business guys get that, if they are smart, they will encourage you to do a constant re-factory process.</p>\n\n<p>You can explain that with a building metaphor. If you don't do refactory you will end with a crappy building with a bad core so you will have problems with the pipes, windows, doors.</p>\n"}]
['https://Stackoverflow.com/questions/77193', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13899/']