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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report

Eliminating duplication

Giorgio Sironi user avatar by
Giorgio Sironi
·
Mar. 10, 11 · Interview
Like (1)
Save
Tweet
Share
7.38K Views

Join the DZone community and get the full member experience.

Join For Free

The title of this article is Eliminating duplication, and when you read that I think you will have guessed I would be talking about code. Of course I will dedicate some space to code-related issues, but not only: duplication is a monster with many heads, that can be found outside of code.

But let's start with it.

Code, of course

The simplest form of code duplication is a group of lines of code which are copied and pasted. They will quickly go out of sync with their original source, resulting in reappearance of bugs and high costs of refactoring (due to all the places where you have to refactor exactly the same code).

But there also many non-obvious duplication that we should target, like:

  • calls to an object which are always made together, a sign of too much fine-grained interface.
  • Needless parallel hierarchies which have to be kept parallel.
  • Multiple implementations of an interface which should actually be Bridges.

Speaking about not actual code, but about CTRL + C, CTRL + Vcomments

Your docblocks (or Javadoc) should not tell me anything that is already in the code.

Comments can be often eliminated by renaming variables and extracting methods and classes. It's more difficult for a method name to get outdated with respect to its own code than for a comment, which if usually filtered out by our minds (which act like a compiler sometimes, stripping everything).

When you write clean code, comments are duplication and can should be deleted.

Speaking about not actual code, but how you write it

How many time I wrote classdef for a Matlab class in this month? Too many, and the next thing I have to do is to configure some snippets to generate classes or methods. The same can be done for every language, I use vim but many editors allows you to define snippets.

How many times I moved my hands from the keyboard to the mouse? I'm learning or setting up more and more keyboard shortcuts.

How many times I looked at the keyboard today? Touch typing really helps in speed and accuracy, as I don't have to continuously switch my eyes direction between screen and keyboard.

And speaking about writing articles: I switched to Dropbox instead of rsync to avoid issuing those commands all the time. Look for your repeated commands in the shell with:

history |awk '{print $2}' | sort | uniq -c | sort -n | tail

and make an alias for them, or find a way to avoid typing them all the time.

However, we're not confined to code

The problem of duplication is always the same: that perfect duplicates do not exist. What is replicated multiple times over space or time won't stay always duplicated, but will get out of sync or will be duplicated incorrectly.

Duplicated incorrectly? Did my pc have corrupted Ram? No, but when we duplicate things over time by redoing them, we have the natural human tendency to not duplicate perfectly. That lead us to the next point.

Test automation

Every time you make a manual test, this test is prone to be repeated in another way (unless you are very, very careful in describing the procedure to follow.) Worse, that test can be forgotten: if you extend the analogy to test suites, forgotten tests are the manifestation of the the inability of duplicating a manual test suite perfectly.

Manual tests are boring to execute, especially in regression settings, and this is already a reason for automate them. Failure to replicate them perfectly is another.

Automation in Continuos Integration follows the same logic: the build steps are often so complex that forgetting one of them or making an error would be the norm. So you can automate completely the chain from commit to release (or to deployment), avoiding duplicating the same steps by hand every time.

Project management tools instead of different sheets and documents

Why we use many online, or however computer-based, project management tool? Of course, for managing everything in one place, but you have to be careful not introducing duplication between the computer database and your paperwork; they will certainly get out of sync. One of the key practices of the Getting Things Done framework for time management is to manage everything in one place, so that you don't have to search for post-it under three different desks, and you can maintain a focused mind when you're working, because you know you don't have to keep in your brain RAM unrelated things.

It's not about having an electronic board with fancy features like easy editing: it's about having a single board which can be accessed everywhere without duplicating via faxes and prints. For example, I use a paper notepad for my GTD process phase (collecting thoughts and possible TODOs) on paper and .txt files in Dropbox for the GTD plan phase: there is no overlap between them, thus I find myself comfortable even without a central electronic management system.

So if you work with Uml diagrams in your office, and you write them with pencil on paper, why use an online tool? If you have telecommuting colleagues, you are forced to do so, but for a colocated team just prescribe that all diagrams should be kept on paper (pencil is editable). No old files in an unreadable format on the server. Agile methodologies indeed are favorable towards paper.

Take-home points

So one of the programmer's jobs is to eliminate duplication: from code, from actions, from managegement tools, from documentation. Avoiding boring and repetitive tasks often puts the fun back in programming.

Now think about one duplicated thing you did yesterday and today and figure out a way to avoid doing it tomorrow.

code style

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Cloud Performance Engineering
  • Choosing the Right Framework for Your Project
  • Configure Kubernetes Health Checks
  • What Is QA as a Service?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • 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: