DZone
DevOps Zone
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
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > DevOps Zone > Duplication Vs. Redundancy in Code

Duplication Vs. Redundancy in Code

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

David Bernstein user avatar by
David Bernstein
CORE ·
Dec. 08, 16 · DevOps Zone · Opinion
Like (2)
Save
Tweet
10.17K Views

Join the DZone community and get the full member experience.

Join For Free

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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • ETL/ELT on Kubernetes With Airbyte
  • How to Build Security for Your SaaS User Communications
  • How Low Code Demands More Creativity From Developers
  • Monolith vs Microservices Architecture: To Split or Not to Split?

Comments

DevOps Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo