Software Design Principles: Doing Little Things Right

Written by kamalkishor1991 | Published 2020/03/14
Tech Story Tags: programming | software-engineering | software-development | software-design | coding | code-quality | design-principles | design-patterns

TLDR Software Design Principles: Doing Little Things Right. Do small things that are almost always win-win situations. Track your code quality believes by your actions. Test-driven development is the biggest value of designing something right. Don’t use variables for non-obvious things like returning -1 for special cases. Have a consistent, strict meaning of variables with a good descriptive name. Use nulls properly with a single meaning. Use variables to represent concepts. Use variable names. Use.via the TL;DR App

Designing software systems is about tradeoffs and making tradeoff decisions is hard. You always feel like you are loosing one thing or the other but that’s not what we are going to talk about today.
We are going to talk about small things that are almost always win-win situations. I am the happiest when I find a solution that’s win-win in all aspects and does not have a downside. That’s your first priority while designing systems. To find some elegant solutions that reduce complexity.
Based on my own mistakes, code reviews, and experience from reading other people's code I am trying to list down some of the win-win situations that people usually don’t focus on while writing code. People usually agree with these things but they certainly do not act as they do.

Track your code quality believes by your actions

Most of the time people do not disagree on something unless they themselves have to do it. For example, if you talk to most people about writing small methods you won’t even find a single person who disagrees with that but if you look at most of the written code you will find that people do not act as they believe in small methods. So pay attention to what you think you believe and how you actually act. This will help you to actually improve in a real actionable manner.

Test-driven development

Most often tests are sold by saying that they will catch the regressions and you can change code later on without worrying about if something will break and its certainly true.
But I think the biggest value of doing test-driven development is designing something right. If you just focus on minimizing writing tests and making them simpler before writing actual code you will realize that your design is automatically right and you already got most of the things that are considered good. Like well defined small methods, well-organized dependencies, less coupling, and no global state etc. Because all of these things are harder to tests.
Focus on writing simple, smaller and concise tests and everything else will follow.

Small methods/functions

Acknowledge that this is hard but a learnable skill to automatically do this. Once you are good at this lot of things become simpler.

Descriptive variable names

There are only two hard things in Computer Science: cache invalidation and naming things.
— Phil Karlton
This is certainly true and it makes a lot of difference. Use variables to represent concepts. Don’t use variables for non-obvious things like returning -1 for special cases. Have a consistent, strict meaning of variables with a good descriptive name. Use nulls properly with a single meaning. Practicing this means you are automatically writing better code.
Here is a good article with some advice. (20 Tips for better naming)
These are some of those things that you can improve on an be better permanently and once you do them unconsciously they do not cost you much time.
Cheers and happy coding!

Published by HackerNoon on 2020/03/14