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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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
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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Evolutionary Architecture: A Solution to the Lost Art of Software Design
  • Software Design Quality
  • The Invisible Artistry of Backend Development
  • Decision-Making Model: SOLVED

Trending

  • My LLM Journey as a Software Engineer Exploring a New Domain
  • The 4 R’s of Pipeline Reliability: Designing Data Systems That Last
  • The Modern Data Stack Is Overrated — Here’s What Works
  • Rethinking Recruitment: A Journey Through Hiring Practices

Software Design Principles DRY and KISS

Obeying the tenets these principles will save you, and any developers who modify after you, significant time and frustration.

By 
Arvind Singh Baghel user avatar
Arvind Singh Baghel
·
May. 14, 18 · Opinion
Likes (4)
Comment
Save
Tweet
Share
14.1K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I am going to explore software design principles and their benefits, why design principles are useful for us, and how to implement them in our daily programming. We will explore the DRY and KISS software design principles.

The DRY Principle – Don’t Repeat Yourself

DRY stand for "Don’t Repeat Yourself," a basic principle of software development aimed to reduce repetition of information. The DRY principle is stated as, “Every piece of knowledge or logic must have a single, unambiguous, representation within a system."

Violations of DRY:

“We enjoy typing” (or, “Wasting everyone’s time."): "We enjoy typing," means writing the same code or logic again and again. It will be difficult to manage the code and if the logic changes then we have to make changes in all the places where we have written the code, thereby wasting everyone's time.

How to Achieve DRY:

To avoid violating the DRY principle, divide your system into pieces. Divide your code and logic into smaller reusable units and use that code by calling it where you want. Don’t write lengthy methods, but divide logic and try to use the existing piece in your method.

DRY Benefits

Less code is good, it saves time and effort, is easy to maintain, and also reduces the chances of bugs.

One good example of the DRY principle is the helper class in enterprise libraries, in which every piece of code is unique in the libraries and helper classes.

KISS - Keep It Simple, Stupid

KISS principle keeps code simple, clear, and easy to understand. Programming languages are for humans to understand, so keep coding simple and straight, to be understood by human beings. Keep your methods small each method should never be more than 40-50 lines.

Each method should only solve one small problem, not many use cases. If you have a lot of conditions in the method, break these out into smaller methods. It will not only be easier to read and maintain but also can find bugs a lot faster.

Violations of KISS:

We have all experienced situations in which we had work to do in the project and found some messy code. "Why they have written these unnecessary lines and conditions when we could do the same thing in just 2-3 lines?" Just have a look at the two codes shown below. Both methods are doing the same thing, but which one would you use?

public String weekday1(int day) {
switch (day) {
case 1:
return “Monday”;
case 2:
return “Tuesday”;
case 3:
return “Wednesday”;
case 4:
return “Thursday”;
case 5:
return “Friday”;
case 6:
return “Saturday”;
case 7:
return “Sunday”;
default:
throw new InvalidOperationException(“day must be in range 1 to 7”);
}
}
public String weekday2(int day) {
if ((day < 1) || (day > 7)) throw new InvalidOperationException(“day must be in range 1 to 7”);
string[] days = {
“Monday”,
“Tuesday”,
“Wednesday”,
“Thursday”,
“Friday”,
“Saturday”,
“Sunday”
};
return days[day – 1];
}


How to Achieve the KISS principle:

To avoid violating the KISS principle try to write the simplest code. Think of many solutions to your problem and choose the best one and transform that into your code. Wherever there is lengthy code, divide that into multiple methods, right-click and refactor in the editor. Try to write small blocks of code which do a single task.

Benefits of KISS:

If we have some badly-written functionality by one developer, and if we ask further developers to make modifications in that code, then first he has to understand the code, which will be more time-consuming than it has to be. If the code is written simply, then there will not be any difficulty in understanding that code, it will be easier to modify, and will take significantly less time. 

Summary

While writing any code or module, keep software design principles in mind and use them wisely. Make them your habit so you won't need to keep remembering every time; it will save development time and make your software module robust, maintainable, and extendable. 

KISS Software design Software development Design

Published at DZone with permission of Arvind Singh Baghel, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Evolutionary Architecture: A Solution to the Lost Art of Software Design
  • Software Design Quality
  • The Invisible Artistry of Backend Development
  • Decision-Making Model: SOLVED

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!