DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How Are Autonomous Vehicles Changing Microcontroller Use?
  • Simplify Database Geo-Redundancy Backup With Cloud Storage Services

Trending

  • How to Submit a Post to DZone
  • Designing Memory Architecture for Stateful AI Agents: Short-Term Context and Long-Term Persistence
  • Part 4: Multi-Agent Orchestration — Pairing Goose With Quarkus Flow State Machines
  • Member Spotlight: Shai Almong

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

Duplication Vs. Redundancy in Code

''Redundancy'' may be a better word choice than ''duplication'' when talking about code quality. Why does it matter?

By 
David Bernstein
·
Dec. 08, 16 · Opinion
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
18.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

You may have noticed that I don’t use the XP term duplication when talking about code quality. I prefer to use the term redundancy instead. This is because duplication is the most obvious form of redundancy but redundancy can take many other forms that are far more subtle and harder to detect.

When I ask developers if non-identical code can be redundant, they say yes. Think of a “for” loop and a “for each” loop iterating through the same collection.

When I ask developers if identical code can be non-redundant, they have a harder time answering me. However, after some thought, they realize that it’s also true. For example, a line of code that reads “index++;” can be used to iterate through a list of names in one part of the code and a list of numbers in another part of the code.

Redundancy is not a repetition of form, but rather a repetition of intent. We are trying to do the same thing in multiple places and that makes it redundant.

Sometimes, I can’t see the redundancy in my code, but I recognize when I write a redundant test that my code must also be redundant.

I say that 95 percent of all redundancy is easy to spot in code, but that last five percent is worth uncovering even if it takes an extra effort because I find that that last little bit of redundancy often hides the essence of a good design and when I remove it, I suddenly see patterns that I hadn’t noticed before.

In his deceptively simple and excellent book, Test-Driven Development By Example, Kent Beck says that if you pay attention to removing duplication in your code and in your test, you’ll end up with good quality code and good quality tests. He is right, but the same could be said about any of the other good code qualities such as cohesion or encapsulation. When you improve one code quality, the others tend to also improve. That’s because they’re facets of the same gem, which is good code. When you improve one aspect of code and you see other aspects of code also improve, then you know you’re on the right track.

Redundancy (engineering)

Published at DZone with permission of David Bernstein. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How Are Autonomous Vehicles Changing Microcontroller Use?
  • Simplify Database Geo-Redundancy Backup With Cloud Storage Services

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook