A series of shapes progressing from a square with rounded corners to a circle. Symbolizes gradual transformation as is required by true refactoring.

Refactoring Admits No Error

Kent Beck once said:

Make the change easy, then make the easy change.

This is a very concise way of saying that you have to maintain and update your code’s design.

The long-term success of a software product depends largely on its design – on the shape of the code.

Designs that are unhelpful resist change. If you want to add a new feature and that addition is easy, then the design is suited to accepting that new feature. However, if you want to add a feature and that addition is hard, the design is not suited to naturally accept that feature.

As shorthand, we call software that is organized so that change is almost always hard “bad code”.

But that doesn’t mean we can be complacent when we have good code. Nor does it mean code that resists one particular change is automatically bad.

To really be successful, you need to keep the design clean. You can’t predict what changes you will need to make, so you will sometimes need to alter your design to support a new feature.

The best way to accomplish this is to change the design first and then add the new functionality. In other words, before you even attempt to add the functionality, you need to change the design so that it will naturally support the functionality, and only then do you add the new functionality.

This process is beneficial for a number of reasons:

  • It guarantees that designs stay up to date
  • It discourages kludgy workarounds
  • It is actually cheaper than just trying to “hack it in”
  • It prevents decay in your codebase

An implication of this fact is that, when you are preparing code to accept a new feature that its design can’t currently accommodate, you really should only change design.

That’s What Tests Are For, Right?

Often, when I bring this up with someone who has a disciplined view of what software professionalism looks like, their response is “That’s what TDD is for!”

Tests are great. I love TDD. Nothing in this post, or any other of my writings, should be construed as a disparagement of tests. In fact, I think we should have this as one of our highest rules:

A well-designed and maintained test suite being necessary to the freedom of a codebase, the right to build and execute tests shall not be infringed.

That said, if you think tests help you with the problem of needing to update design, I’ve got bad news for you: The help they provide is limited at best.

For one thing, there is no guarantee that your test suite covers every behavior in your system. We try to write tests for every behavior – especially for every behavior that matters to a stakeholder – but there is no way to be sure.

For another, not all code is testable in its present form. Legacy code comes to mind, and there is a vast amount of it serving as a foundation for our modern economy. Code that connects to external systems — APIs, queues, payment gateways — is another example of code that isn’t practical to test directly. And, of course, tests themselves can’t be tested in any meaningful way.

In the dream, every behavior in a codebase is specified by exactly one test. When you awaken to the harsh reality of your circumstances, this is simply not the case and likely never will be.

So if tests can’t guarantee safety, how do we know we’re truly refactoring? I’ll come back to that in toward the end.

The Word “Refactoring” and Its Very Specific Meaning

Many use the word “refactoring” to mean simply “changing design”. That, however, is not what it means at all. One could argue that “just changing design” is more or less what the book Refactoring was arguing against.

Refactoring, specifically, means changing design without changing behavior.

This does not mean that some of the changes didn’t change behavior. To be considered refactoring, all of the changes in a sequence must preserve behavior.

It doesn’t mean that changes mostly preserve behavior. To be refactoring, each step must have literally no impact on function.

Most importantly: It doesn’t mean you’re “pretty sure” or “hoping” that behavior was preserved. If you’re not completely confident, it wasn’t refactoring.

Refactoring is a highly-disciplined approach to changing design that manifests zero tolerance for altering functionality.

“But How?”

When I finally get through to someone and help them see what it really is, the response is often incredulity.

“Sure. [The real] definition of refactoring would be great,” they say, “if it were possible.”

I assure you: It is possible, and a focus on continuity is the key.

Refactoring – true refactoring – is a deeply disciplined and rigorous approach to changing design.

It is founded on small, provably transformative operations. Each operation is something that you, and any developer who is watching, can easily prove with math does not modify behavior.

Imagine adding a new local variable to a method. You’re not modifying any existing methods. You’re not changing how a method is used. You’re not forcing that method to be used. It has a unique name within the method.

You know that won’t change behavior. Yet it observably has changed design.

Such tiny changes are so small that they can safely be considered smooth transformational acts applied to the design – as if you’re molding a lump of clay.

Any reliable automation and any manual step that is provably transformative can be considered an “atom” of refactoring.

“But How?”

From these atoms of refactoring one can build larger structures.

Continuing the chemistry analogy, we might think of larger operations like emerging a class from the local variables in an algorithm as “molecules”.

Then we can assemble those operations into still larger operations, such as transforming a type code field into a polymorphic hierarchy. This is where the chemistry analogy starts to lose its effectiveness. Chemistry has larger structures, but their names aren’t widely known. The point is that they’re just bigger arrangements in the same space.

It is recursively macrocosmic in this way. You can build higher and higher levels of refactoring operations, each out of lower-order sequences.

The reason this is possible is one of the worst-advertised facts in software development.

Consider some design A. Now imagine a change that moves your software from design A to A'. If you know for a fact that this step does not change behavior, then you know that A == A'. Now, if we consider another change that moves from A' to A'' and makes the same guarantee, that means we know that A' == A''.

The transitive property is then what makes this all work and ultimately tells us that the entire sequence was provably transformative: A == A''.

This means that you know that the larger operation comprising the two smaller ones, so you can apply the exact same reasoning to two such larger operations.

For example, consider the following progression:

				
					if (X >= 1) F();
if (X - 1 >= 1 - 1) F();
if (X - 1 >= 0) F();
				
			

Each of those steps is provably the same behavior as its predecessor and, therefore, we know that if (X >= 1) is the same as if (X - 1 >= 0). You can then assembly that step into even larger steps that you have proven are safe, like if (X >= 1) → if (X > 0) (for integers).

If you know these practices and techniques, you can literally transform a legacy code system with procedural (if you’re lucky!) logic embedded directly in GUI code into something that can easily be tested, changed, and understood. You can spend days gradually transforming the design in this way and never have a reason to worry that you might have broken something.

Why it Matters

When I was in the Boy Scouts, I was taught – and then learned in a very practical way – that small things can cause great harm. Common examples when hiking in the woods are hotspots, which turn to blisters and the sores, and pebbles or debris in your boots, which can cut and cause infections.

The principle which underlies this also applies to changing design and it’s why true refactoring is so very important.

All large changes are really strings of smaller changes.

When you apply true refactoring, you can manage these changes and use them to elegantly emerge any design structure you need, even from seemingly chaotic spaghetti code.

If, however, you allow even one small modification of behavior into your sequence, then every change after that has the potential to impact functionality in unforeseen ways. An ostensibly small change that seemed innocuous, at first, can fester into something truly catastrophic.

For this reason, refactoring must have zero tolerance for the admission of changes to behavior. For the reasons already outlined earlier, the only workable method for ensuring that function remains unchanged is to ensure that each atomic step in a refactoring operation is provably transformative.

A New Standard for Refactoring

That brings us back to the practical question: how do you know if you’re refactoring?

Here’s the standard I propose: Your measure of true refactoring is the time from random interruption to demo-ability.

I’ll explain more in a few paragraphs. First, I’ll need to give you some context.

I train with pistols, among other things. One of the things you practice in this kind of training is the timing of your draw. To do this training, we use a device called a “shot timer”.

It can be configured to beep at a random time (e.g., sometime between 1 and 5 seconds from now), and it records the time to your first shots and the increments (“splits”) to subsequent shots.

This, at once, provides a training mechanism (the random buzzer to initiate action) and an optimization mechanism (telling you how long it takes to start and complete a pattern).

I propose that you use a similar mechanism to augment your refactoring skills. When you start making changes to a system, set a timer to go off some random amount of time between a floor and a ceiling. For instance “between 5 and 15 minutes from now”.

When that timer goes off, immediately stop changing the system and start trying to return the system into a demo-able state.

If you were truly refactoring, all your changes were smooth, small, and provably transformative. Notwithstanding things like compile time, you should be able to more or less immediately demonstrate that the system works the same way it did before you started altering design.

If, on the other hand, you have to do a bunch of work to get something to compile, or spend time hunting down and finishing changes, you can be pretty sure that whatever you were doing was not refactoring.

Just as a shot timer measures a marksman’s readiness under pressure, this timer will measure your readiness as a refactorer. Both demand discipline, zero hesitation, and zero tolerance for sloppiness.

Use this method once a week. Track your “draw time” and drive it down. I guarantee it will make you better at refactoring and a better developer.

I recommend giving our Refactoring Shot Timer a try with this approach.

Get our Newsletter

Subscribe

Privacy Policy

Effective date: 1st day of January, 2023

www.producore.com (the “Site”) is owned and operated by Producore LLC. Producore LLC can be contacted at:

Phone: +1-307-226-2200
Email: [email protected]
Mailing Address: 13601 W MCMILLAN RD STE 102-277, BOISE ID 83713-2025

Purpose

The purpose of this privacy policy (this “Privacy Policy”) is to inform users of our Site of the following:

  1. The personal data we will collect;

  2. Use of collected data;

  3. Who has access to the data collected;

  4. The rights of Site users; and

  5. The Site’s cookie policy.

This Privacy Policy applies in addition to the terms and conditions of our Site.

Consent

By using our Site users agree that they consent to:

  1. The conditions set out in this Privacy Policy; and

  2. The collection, use, and retention of the data listed in this Privacy Policy.

Personal Data We Collect

We only collect data that helps us achieve the purpose set out in this Privacy Policy. We will not collect any additional data beyond the data listed below without notifying you first.

Data Collected Automatically

When you visit and use our Site, we may automatically collect and store the following information:

  1. IP address;

  2. Location;

  3. Hardware and software details;

  4. Clicked links; and

  5. Content viewed.

Data Collected in a Non-Automatic Way

We may also collect the following data when you perform certain functions on our Site:

  1. First and last name;

  2. Email address;

  3. Phone number;

  4. Address; and

  5. Payment information.

This data may be collected using the following methods:

  1. Creating an account; and

  2. Submitting an order.

How We Use Personal Data

Data collected on our Site will only be used for the purposes specified in this Privacy Policy or indicated on the relevant pages of our Site. We will not use your data beyond what we disclose in this Privacy Policy.

The data we collect automatically is used for the following purposes:

  1. Statistics for internal-use only to improve our website and our services..

The data we collect when the user performs certain functions may be used for the following purposes:

  1. Communication; and

  2. Processing payments.

Who We Share Personal Data With

Employees

We may disclose user data to any member of our organization who reasonably needs access to user data to achieve the purposes set out in this Privacy Policy.

Other Disclosures

We will not sell or share your data with other third parties, except in the following cases:

  1. If the law requires it;

  2. If it is required for any legal proceeding;

  3. To prove or protect our legal rights; and

  4. To buyers or potential buyers of this company in the event that we seek to sell the company.

If you follow hyperlinks from our Site to another Site, please note that we are not responsible for and have no control over their privacy policies and practices.

How Long We Store Personal Data

User data will be stored until the purpose the data was collected for has been achieved.

You will be notified if your data is kept for longer than this period.

How We Protect Your Personal Data

In order to protect your security, we use the strongest available browser encryption and store all of our data on servers in secure facilities. All data is only accessible to our employees. Our employees are bound by strict confidentiality agreements and a breach of this agreement would result in the employee’s termination.

While we take all reasonable precautions to ensure that user data is secure and that users are protected, there always remains the risk of harm. The Internet as a whole can be insecure at times and therefore we are unable to guarantee the security of user data beyond what is reasonably practical.

Children

We do not knowingly collect or use personal data from children under 13 years of age. If we learn that we have collected personal data from a child under 13 years of age, the personal data will be deleted as soon as possible. If a child under 13 years of age has provided us with personal data their parent or guardian may contact our privacy officer.

How to Access, Modify, Delete, or Challenge the Data Collected

If you would like to know if we have collected your personal data, how we have used your personal data, if we have disclosed your personal data and to who we disclosed your personal data, or if you would like your data to be deleted or modified in any way, please contact our privacy officer at:

[email protected]

(307) 226-2200

300 N. Center Street, Unit 6, Casper, WY 82601

Do Not Track Notice

Do Not Track (“DNT”) is a privacy preference that you can set in certain web browsers. We do not track the users of our Site over time and across third party websites and therefore do not respond to browser-initiated DNT signals.

How to Opt-Out of Data Collection, Use or Disclosure

In addition to the method(s) described in the How to Access, Modify, Delete, or Challenge the Data Collected section, we provide the following specific opt-out methods for the forms of collection, use, or disclosure of your personal data specified below:

You can opt-out of the use of your personal data for marketing emails. You can opt-out by clicking “unsubscribe” on the bottom of any marketing email or updating your email preferences under “Your Account”

Cookie Policy

A cookie is a small file, stored on a user’s hard drive by a website. Its purpose is to collect data relating to the user’s browsing habits. You can choose to be notified each time a cookie is transmitted. You can also choose to disable cookies entirely in your internet browser, but this may decrease the quality of your user experience.

We use the following types of cookies on our Site:

  1. Functional cookies are used to remember the selections you make on our Site so that your selections are saved for your next visits; and

  2. Analytical cookies allow us to improve the design and functionality of our Site by collecting data on how you access our Site, for example data on the content you access, how long you stay on our Site, etc.

Modifications

This Privacy Policy may be amended from time to time in order to maintain compliance with the law and to reflect any changes to our data collection process. When we amend this Privacy Policy we will update the “Effective Date” at the top of this Privacy Policy. We recommend that our users periodically review our Privacy Policy to ensure that they are notified of any updates. If necessary, we may notify users by email of changes to this Privacy Policy.

Contact Information

If you have any questions, concerns or complaints, you can contact our privacy officer at:

Phone: +1-307-226-2200
Email: [email protected]
Mailing Address: 13601 W MCMILLAN RD STE 102-277, BOISE ID 83713-2025

Terms & Conditions

These terms and conditions (the “Terms and Conditions”) govern the use of www.producore.com (the “Site”). This Site is owned and operated by Producore LLC.

By using this Site, you indicate that you have read and understand these Terms and Conditions and agree to abide by them at all times.

THESE TERMS AND CONDITIONS CONTAIN A DISPUTE RESOLUTION CLAUSE THAT IMPACTS YOUR RIGHTS ABOUT HOW TO RESOLVE DISPUTES. PLEASE READ IT CAREFULLY.

Intellectual Property

All content published and made available on our Site is the property of Producore LLC and the Site’s creators. This includes, but is not limited to images, text, logos, documents, downloadable files and anything that contributes to the composition of our Site.

Acceptable Use

As a user of our Site, you agree to use our Site legally, not to use our Site for illegal purposes, and not to:

  • Harass or mistreat other users of our Site;

  • Violate the rights of other users of our Site;

  • Violate the intellectual property rights of the Site owners or any third party to the Site;

  • Hack into the account of another user of the Site;

  • Act in any way that could be considered fraudulent; or

  • Post any material that may be deemed inappropriate or offensive.

If we believe you are using our Site illegally or in a manner that violates these Terms and Conditions, we reserve the right to limit, suspend or terminate your access to our Site. We also reserve the right to take any legal steps necessary to prevent you from accessing our Site.

User Contributions

Users may post the following information on our Site:

  • Public comments.

By posting publicly on our Site, you agree not to act illegally or violate these Terms and Conditions.

Accounts

When you create an account on our Site, you agree to the following:

  1. You are solely responsible for your account and the security and privacy of your account, including passwords or sensitive information attached to that account; and

  2. All personal information you provide to us through your account is up to date, accurate, and truthful and that you will update your personal information if it changes.

We reserve the right to suspend or terminate your account if you are using our Site illegally or if you violate these Terms and Conditions.

Sale of Goods And Services

These Terms and Conditions govern the sale of goods and services available on our Site.

The following goods are available on our Site:

  • Templates; and

  • Guides.

The following services are available on our Site:

  • Training courses;

  • Coaching services; and

  • Consulting services.

The services will be paid for in full when the services are ordered.

These Terms and Conditions apply to all the goods and services that are displayed on our Site at the time you access it. This includes all products listed as being out of stock. All information, descriptions, or images that we provide about our goods and services are as accurate as possible. However, we are not legally bound by such information, descriptions, or images as we cannot guarantee the accuracy of all goods and services we provide. You agree to purchase goods and services from our Site at your own risk.

We reserve the right to modify, reject or cancel your order whenever it becomes necessary. If we cancel your order and have already processed your payment, we will give you a refund equal to the amount you paid. You agree that it is your responsibility to monitor your payment instrument to verify receipt of any refund.

User Goods and Services

Our Site allows users to sell goods and services. We do not assume any responsibility for the goods and services users sell on our Site. We cannot guarantee the quality or accuracy of any goods and services sold by users on our Site. However, if we are made aware that a user is violating these Terms and Conditions, we reserve the right to suspend or prohibit the user from selling goods and services on our Site.

Subscriptions

Your subscription does not automatically renew. You will be notified before your next payment is due and must authorize that payment in order for your subscription to continue.

You may cancel your subscription anytime before the renewal date and up to 14 days after renewal.

Payments

We accept the following payment methods on our Site:

  • Credit Card;

  • Debit; and

  • Direct Debit.

When you provide us with your payment information, you authorize our use of and access to the payment instrument you have chosen to use. By providing us with your payment information, you authorize us to charge the amount due to this payment instrument.

If we believe your payment has violated any law or these Terms and Conditions, we reserve the right to cancel or reverse your transaction.

Consumer Protection Law

Where any consumer protection legislation in your jurisdiction applies and cannot be excluded, these Terms and Conditions will not limit your legal rights and remedies under that legislation. These Terms and Conditions will be read subject to the mandatory provisions of that legislation. If there is a conflict between these Terms and Conditions and that legislation, the mandatory provisions of the legislation will apply.

Limitation of Liability

Producore LLC and our directors, officers, agents, employees, subsidiaries, and affiliates will not be liable for any actions, claims, losses, damages, liabilities and expenses including legal fees from your use of the Site.

Indemnity

Except where prohibited by law, by using this Site you indemnify and hold harmless Producore LLC and our directors, officers, agents, employees, subsidiaries, and affiliates from any actions, claims, losses, damages, liabilities and expenses including legal fees arising out of your use of our Site or your violation of these Terms and Conditions.

Applicable Law

These Terms and Conditions are governed by the laws of the State of Wyoming.

Dispute Resolution

Subject to any exceptions specified in these Terms and Conditions, if you and Producore LLC are unable to resolve any dispute through informal discussion, then you and Producore LLC agree to submit the issue first before a non-binding mediator and to an arbitrator in the event that mediation fails. The decision of the arbitrator will be final and binding. Any mediator or arbitrator must be a neutral party acceptable to both you and Producore LLC. The costs of any mediation or arbitration will be shared equally between you and Producore LLC.

Notwithstanding any other provision in these Terms and Conditions, you and Producore LLC agree that you both retain the right to bring an action in small claims court and to bring an action for injunctive relief or intellectual property infringement.

Severability

If at any time any of the provisions set forth in these Terms and Conditions are found to be inconsistent or invalid under applicable laws, those provisions will be deemed void and will be removed from these Terms and Conditions. All other provisions will not be affected by the removal and the rest of these Terms and Conditions will still be considered valid.

Changes

These Terms and Conditions may be amended from time to time in order to maintain compliance with the law and to reflect any changes to the way we operate our Site and the way we expect users to behave on our Site. We will notify users by email of changes to these Terms and Conditions or post a notice on our Site.

Contact Details

Please contact us if you have any questions or concerns. Our contact details are as follows:
Phone: +1-307-226-2200
Email: [email protected]
Mailing Address: 13601 W MCMILLAN RD STE 102-277, BOISE ID 83713-2025

Effective Date

1st day of January, 2023