3 software development principles I wish I knew earlier in my career

petarivanovv9

Petar Ivanov

Posted on September 16, 2024

3 software development principles I wish I knew earlier in my career

Intro

Many software development principles are worth exploring and applying.
However, I found 3 of them to be extremely helpful and powerful throughout my career.
They shaped the way I write software and ship products.
They’re fundamental building blocks if you want to grow into a Regular and Senior Developer.
Today, I want to share them with you, so you can start applying them and skyrocket your career trajectory.

After reading this article, you’ll learn:

  • what is YAGNI
  • what is KISS
  • what is DRY
  • the importance of these 3 principles

3 Coding Principles I wish I knew earlier

YAGNI: You Aren’t Gonna Need It

The key essence of this principle is:

💡 Don’t add features or functionality to our software that we currently don’t need.

The YAGNI rule is about not adding stuff to your project or codebase just because you think you might need it later. Most of the time, you won’t end up needing it, and it just wastes time. It’s better to stick to what you know you need at the moment. Don’t add code for the imaginary future.

⛔ Avoid

interface User {
  name: string;
  age: number;
  // Future-proofing for possible new features
  address?: string;
  phoneNumber?: string;
}

function createUser(name: string, age: number): User {
  // Simplified for current needs
  return { name, age };
}
Enter fullscreen mode Exit fullscreen mode

✅ Prefer

interface User {
  name: string;
  age: number;
}

function createUser(name: string, age: number): User {
  return { name, age };
}
Enter fullscreen mode Exit fullscreen mode

KISS: Keep It Simple, Stupid

The key essence of this principle is:

💡 Don’t add unnecessary complexity to our software.

The KISS rule means keeping our code easy to read and understand. Instead of making things complicated and “smart”, try to write code that’s straight to the point. This makes it easier for you and others to keep track of what’s going on and fix things when they go wrong.

Instead of being too "smart" in your code, think about your colleagues and future teammates. Maybe it's better to write 2-3 lines more, but guarantee that your future teammates will understand it.

⛔ Avoid

function getEvenNumbers(numbers: number[]): number[] {
  let evenNumbers: number[] = [];

  for (let i = 0; i < numbers.length; i++) {
    if (numbers[i] % 2 === 0) {
      evenNumbers.push(numbers[i]);
    }
  }

  return evenNumbers;
}
Enter fullscreen mode Exit fullscreen mode

✅ Prefer

function getEvenNumbers(numbers: number[]): number[] {
  return numbers.filter(number => number % 2 === 0);
}
Enter fullscreen mode Exit fullscreen mode

It’s important to note that sometimes adding more layers of abstraction in our codebase may seem to conflict with the KISS principle because we add layers of complexity. However, when done carefully, abstraction can simplify the overall design by hiding complex logic behind simpler interfaces or functions. In the end, it makes our code easier to read, understand, and maintain which is our end goal.

DRY: Don’t Repeat Yourself

The key essence of this principle is:

💡 Don’t duplicate code or data in our software.

The DRY rule is about not writing the same code over and over again. If you find yourself doing the same thing in several places, find a way to do it just once. This makes your code cleaner and easier to change later.

⛔ Avoid

interface Product {
  id: number;
  name: string;
  price: number;
}

function getProductName(product: Product): string {
  return product.name;
}

function getProductPrice(product: Product): number {
  return product.price;
}
Enter fullscreen mode Exit fullscreen mode

✅ Prefer

interface Product {
  id: number;
  name: string;
  price: number;
}


function getProductProperty<T extends keyof Product>(
  product: Product,
  property: T,
): Product[T] {
  return product[property];
}
Enter fullscreen mode Exit fullscreen mode

Note: All examples intent to only illustrate the idea behind each principle. They’re not meant for production.

Conclusion

The YAGNI, KISS, and DRY principles are not just coding strategies. They’re philosophies that guide crafting quality software. They’re foundational elements for professional growth and efficiency.

💡 Life Hack: These principles can be applied in our personal lives as well.

Try them out in your work and see how they can make a difference!

👋 Get in touch

You can find me on LinkedIn.

I share daily practical tips to level up your skills and become a better engineer.

You can learn more about Software Design, JavaScript, React, and Node.js in my newsletter: The T-Shaped Dev.

💖 💪 🙅 🚩
petarivanovv9
Petar Ivanov

Posted on September 16, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related