This content is part of the Essential Guide: How to improve code quality, from teamwork to AI features

Which programming practices alleviate code redundancy?

WET code leaves apps bogged down. Learn how to reduce the challenges brought on by code redundancy by programming based on the DRY principle.

Software developers should strive to reduce code redundancy in their applications. You rarely need to create two elements that perform that same function. If a program looks for a keyboard input, for example, there should be only one routine to gather that input. A second keyboard input routine is unessential at best and inefficient at worst. Additional routines require extra time to create, test and maintain.

Many programmers embrace Don't Repeat Yourself (DRY) as a mantra against code redundancy in software development. The DRY principle goes that the most efficient code, which uses the lowest amount of resources possible, is only represented once within a whole system.

The implementation of DRY code starts with human factors. Plan to design and write modular code from the beginning of a project, and enforce DRY principle results. If the modules are small and reusable from the design phase, the resulting code is much likelier to be DRY. Code reviews also help reinforce the DRY principle and reduce code redundancy. Developers should periodically access implementation guidance to ensure that code meets expectations. Additionally, there are tools that help dev teams manage code and enable easy component sharing.

The inverse of the concept is Write Everything Twice (WET). WET, a snarky term, implies that functions and tasks exist in two or more places throughout the code.

Repetition creates more lines of code, which means more content to read and comment on. More lines of code also mean more opportunity to introduce errors and security flaws, and the executable results are larger to build and deploy. So, there is no significant benefit to any amount of WET code, yet it is all too common in software development.

DRY vs. WET code

An application ends up with WET code through inefficient programming, which is often a fact of life in enterprise projects. Developers create WET code when they merge different code bases or introduce open source libraries with similar features and functions to a project. Adopt and enforce efficiency standards to curtail code redundancy.

Additionally, any code refactoring endeavor should include identification and elimination of WET code, and the project should reinforce the DRY principle.

Improve code quality and standards

When software developers adhere to code standards, it makes the finished product more efficient and readable to other team members. There are a number of ways to shore up programming standards, in addition to a focus on code redundancy.

Reusable code is a huge assist to developers. When developers reuse code, it reduces the effort and time necessary to build basic app components. For example, development teams often pull code from other apps or open source code for simple functions -- as long as the code is written in a way to make it reusable. Developers can adhere to these practices and principles to maximize code reuse.

Developers can also adopt programming conventions or standards related to various application characteristics, such as maintainability, reliability, efficiency and usability. These guidelines inform developers on how to write good code.

Next Steps

Tips for building a DevOps knowledge-sharing culture

Dig Deeper on Software design and development

Cloud Computing
App Architecture
ITOperations
TheServerSide.com
SearchAWS
Close