• My team uses scrum
  • I have currently no task assigned
  • There are no more pending task in the backlog
  • Today is Labor Day for my client.

Not having many things to do today I wanted to start refactoring some code I keep on seeing in the project I am working on, but currently I am not assigned to any sprint task to do any large scale refactoring.

Is it OK in Scrum if I start randomly refactoring code that I have and have not written that always bother me but don't have time other days to fix it because of other days assignments?

What about other days that I have spare time between sprints.

I actually do and believe in continuous refactoring. I always do it on the pieces of code that I am working when assigned a story but what about some other code I see that is not currently related to what I am working on at that moment?

  • meta.programmers.stackexchange.com/questions/6483/…
    – gnat
    Commented Sep 1, 2014 at 16:48
  • I think this is not completely opinion based since I am asking specifically about scrum process. Commented Sep 1, 2014 at 16:50
  • 1
    I suggest editing your question to ask about the drawbacks of refactoring this way. That is more objective, and if there are no drawbacks, it answers your original question. Maybe also look at this question as well to see if the answers help.
    – user22815
    Commented Sep 1, 2014 at 17:04
  • @BЈовић No, I wrote the question on September 1st Commented Sep 3, 2014 at 16:10
  • 1
    @BЈовић Labor day is the first monday of september in the US. May 1st is International Workers' Day. Not being in US I get to work on Labor Day Commented Sep 4, 2014 at 14:24

7 Answers 7


I really don't mean to attack other answers, but is nobody else writing automated tests here? Here's a fun reading from Martin Fowler for anyone doing Scrum without proper software engineering practices. Robert C. Martin also says a lot about this here.

So, to my answer... In short, it goes like this:

Yes, "randomly" refactoring code is allowed in Scrum, as long as the team decides that it should be done. (After all, it is self-organizing)

And now for the long answer:

It's evident that leaving more and more technical debt after each Sprint is a recipe for disaster. Soon, everyone will slow down as the code bocomes more messy; every change will be harder to make because the code is so tangled and messy that it takes longer to find the spots to change than to make the actual change. It gets even worse if you have to make a change in a big and messy module that you know nothing about, it becomes impossible to gain/keep productivity when adding/switching people in the project, and so on.

If a team wants to keep its velocity steady, they must be able to keep the code base clean in order to continuously increment the software. Refactoring is a mandatory practice if you want to keep your velocity throughout the project's life cycle, and if you want to mitigate the risk of adding/switching people on the project, and if you want to be able to make changes in modules you know nothing about, and so on.

However, refactoring is a very dangerous activity. I repeat - it is a very dangerous activity. That is, unless you have enough test coverage to be able to safely and freely change the code base. If you can just hit a button to check if nothing broke, refactoring becomes a very safe activity; so safe, in fact, that it is part of the cycle of TDD, which is the practice that allows you to create such a test suite in the first place.

But, as the teams in Scrum are self organizing, in the end your team must decide what is the right thing to do. I hope to have given you some arguments in the case you have to convince anyone. (Give special attention to the links in the first paragraph, and every other article they point to)

  • 1
    What's enough test coverage to consider refactoring very safe? Randomly changing working code without a purpose to fix bugs is always a risk. Commented Sep 2, 2014 at 3:39
  • 5
    No amount of tests makes refactoring completely safe. SQLite is one of the most tested pieces of software, with total branch coverage, yet they still do emergency bugfix releases all the time.
    – Jan Hudec
    Commented Sep 2, 2014 at 5:42
  • @Petter Refactoring is defined as a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior. A bug is an observable behavior, so it can't be "refactored out". You do use refactoring at a portion of code that you judge would benefit from a better structure, it's not random (hence the quotation marks). However, in order to be absolutely sure that your changes do not affect the observable behavior of the system, you must have 100% test coverage; even if some of it is achieved through manual tests. Commented Sep 2, 2014 at 13:49
  • 1
    I don't disagree that refactoring is NECESSARY. However, even if you have 100% coverage using both white/black box testing techniques the chance of not changing behavior and introducing unforeseen bugs isn't anywhere near zero. Once a class is coded, I almost never see changes break that class. That's not where the bugs occur. Most bugs occur when a class changes because it ends up behaving "slightly" differently with regards to the system, even though it still "technically" does exactly the same thing. e.g. Just made the class thread-safe, ooops now function fails because its call is blocked.
    – Dunk
    Commented Sep 2, 2014 at 14:40
  • 2
    100% code coverage doesn't absolutely prevent introduction of bugs. Although every line of code is tested, not every possible program state will ever be tested.
    – bdsl
    Commented Apr 28, 2016 at 19:12

Scrum doesn't really say anything about refactoring.

What Scrum does say is that if you don't have any tasks within the sprint to work on, you should support the rest of your team to reach the sprint goal. Even if that means fetching coffee for them.
If your team agrees that refactoring the code is the best way you can support them (and that includes having the infrastructure in place to ensure the refactoring doesn't introduce too many new bugs), then by all means go for it.


I'd say no, it's not. This is regardless of the type of work (refactoring, etc).

At minimum, tasks should be created and pushed into your current sprint. The purpose of time tracking is to capture your velocity in order to effectively be able to plot out future sprints. If you're working on things without tracking them, you will impact the velocity and it will not get better over time as it's intended to with proper tracking (you will likely regularly not have enough work because your projected velocity is less than your real velocity).

As for refactoring work in itself, I can go on a tirade about that, but I won't as I don't think it's the core question you're trying to have answered.


I am going to say no as well. Re-factoring often leads to unintended bugs if it is not managed the right way.

As a GM, periodically I would put everyone on another project and spend a week doing code reviews / re-factoring / renaming and enforcing conventions on a project. These re-factoring sprints would almost always be cosmetic in nature. Any functional re-factoring would be planned ahead of time and involve the original developer.

Functional re-factoring should always be planned and coordinated as part of the scrum process so the time can be tracked and all necessary team members are available to validate the process. One developer should not go off changing code written by another off track because most likely it is just going to mess up the current sprint for everyone. Especially when it comes to code merge time.

If it is a project which you are the sole maintainer and it is your own free time then it can be different assuming you take steps to ensure that you don't cause unnecessary delays in your current sprint.

When in doubt, ask your manager.

EDIT: I also want to mention that a given piece of code you do not like may have a certain performance target associated with it. You may not like it but it may be faster than anything you could build that suits how you want to use it. Just another reason why functional re-factoring should always be a managed process.

  • 1
    What do you mean with "cosmetic refactoring"? Commented Sep 2, 2014 at 9:30
  • Function, Class, and Constant names. Moving properties to the top of the file and related functions together. Sometimes moving functions from instance to static. Mostly to ensure a common style of nomenclature and structure is enforced. This creates a sort of consistency across the code base that would never happen naturally. Commented Sep 2, 2014 at 14:04

Scrum does not say anything about refactoring (see a lecture of Robert C. Martin, "The land that scrum forgot").

In Scrum tasks are targeting features of your software specified by the customer, not technical debts to repay by refactoring. These are totally different abstraction levels. The customer mostly is not able to evaluate the neccessity.

Scrum is statistical project management. To get meaningful measures of "how long does it take" you have to know the performance (output per sprint). You compare the estimation and the real duration for a feature for at least more than 1 sprint to get into the statistic. I recommend 5 sprints. But that depends on your team.

The main thing is to keep measures meaningful and comparable to make any forecast possible. That will not be the case if the performance is decreasing because of technical debts.

If you now still think of refactoring tasks you have two problems: 1. A customer, that does not understand, why he has to accept a task that will not produce a new feature 2. You totally distort your statistics and therefore your ability to forecast as you suddenly change a different variable that was not considered in previous sprints

In both cases you compromise the idea of scrum as you want to talk about features with the customer AND make reliable forecasts for "How long does it take?" in a statistical way. To be safe you have to keep your code base in a constant (maybe high) quality.

Refactoring is most of the time an underground task. "Great" refactorings mean that "little" refactorings haven't been processed in the past.

One last note: If you do refactorings make sure you have the component under test you are refactoring. Ohh, you do not have tests? Make a task to write tests. Your customer will be happy to know that the software he is currently using has not enough test coverage...

Keep the technical stuff away from the customer and do your job as a professional developer.


Here is one approach: do both !

Refactoring is often error-prone or more time-consuming that originally estimated as @misterbiscuit points out.

So consider an attempt to do it a draft or a spike. You don't ned to seek approval or advertise if at this stage.

Then, look to include it through one of two channels:

  • an existing ticket that touches the same code / functionality where you can reasonable wrap this in. Reasonably as agreed on with fellow team members.
  • entire a ticket for review at the next ticket grooming (or weekly meeting, etc. if waterfall). At that time you can make the case for it.

Once you get actual buy-in, you can look to apply or redo your spike and having the code actual get merged into the mainline (master, etc.) branch.

This will have several advantages:

  • All your code codes through the same process, gets tested, QA, in the release pipeline, etc.
  • You get formal buy-in, including from the product manager, that refactoring is part of the craft and not something that needs to be 'sneaked in' on a holiday. Ask yourself why you aren't 'sneaking in' an actual feature may help for perspective.
  • You can ask for pairing, code review, qa, devops and all the other support that may be needed for the factoring code change. It will all be official, according to Policy and Procedure and above board.
  • If you are a publicly traded company with SOX compliance you likely want/need to do this sort of formal process (i.e. document it and then follow it).
  • You get a better reputation with both the product manager (change was done quickly) and the development team (codebase was improved).
  • The organization is seeking to care about code quality which is good for productivity, morale, employee retention and many other reasons.
  • The effect on project velocity can be more easily tracked when all work is included. It can be ok not to appoint any points as the presence itself can be used to affect velocity.
  • Developers are likely to see out tools that encourage easier code reviews such as Fisheye, Github, etc.
  • Developers are more likely to see out some basic standards (sometimes documented, sometimes not) that make sharing code and hence refactoring easier. Sometimes a big part of refactoring is picking a style and then applying it broadly (replacing a mixture of approaches with one).

A final comment: Avoid the product manager hearing the word 'random'. They may respond more favourably with 'targeted, strategic, performance enhancing' code upgrade. Or application service pack. Or whatever language gives you coverage.


Random refactoring makes no sense. What makes sense is refactoring of a code that will introduce most benefits. That means :

  • fixing a design or architecture problem
  • improving the implementation

Is it OK in Scrum if I start randomly refactoring code that I have and have not written that always bother me but don't have time other days to fix it because of other days assignments?

From this answer :

Keeping code maintainable needs to be an item on your burn-down list (if you use a Scrum). It is just as important as new development. While it may not seem like something that is "visible to the user", ignoring it increases your technical debt. Down the road when the technical debt piles up enough that your code's lack of maintainability slows down development, the delays in new feature development will be visible to customers.

In my previous work, we had some kind of scrum, with larger sprints (2-3 months). Since we had some delays between sprints (1 month), we used this time to analyze the software, and refactor the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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