Skip to Content
Tidy First?
book

Tidy First?

by Kent Beck
October 2023
Intermediate to advanced
124 pages
1h 58m
English
O'Reilly Media, Inc.
Content preview from Tidy First?

Chapter 2. Dead Code

Delete it. That’s all. If the code doesn’t get executed, just delete it.

Deleting dead code can feel mighty strange. After all, someone took the time and effort to write it. The organization paid for it. There it is. All somebody has to do to make it valuable is call it again. If we need it again, we’ll be sad we deleted it.

I’ll leave it as an exercise for you, tidy reader, to identify all the cognitive biases I just demonstrated.

Sometimes it’s easy to identify dead code. Sometimes, because of extensive use of reflection, it’s not so easy. If you suspect code isn’t used, pre-tidy it by logging its use. Put the pre-tidying into production and wait until you’re confident.

You might ask, “But what if we need it later?” That’s what version control is for. We aren’t really deleting anything. We just don’t have to look at it right now. If (and this is a long string of conditionals) we 1) have a lot of code that 2) isn’t used right now that 3) we want to use in the future 4) in exactly the same way it was originally written and 5) it still works, then yes, we can get it back. Or we can just write it again, and better. But if worse comes to worst, we can always get it back.

As always, delete only a little code in each tidying diff. That way, if it turns out you were wrong it will be relatively easy to revert the change (see Chapter 28). “A little” is a cognitive measure, not a lines-of-code measure. It could be one clause in a conditional (e.g., you see the condition ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Building Micro-Frontends

Building Micro-Frontends

Luca Mezzalira
System Design Masterclass

System Design Masterclass

Rohit Jain Sweet Codey, Suresh Gandhi, Shubham Chandak

Publisher Resources

ISBN: 9781098151232Errata Page