Basic principles that will make your programming life in 2019.

sandipmavani

Sandip Mavani

Posted on January 10, 2019

 Basic principles that will make your programming life in 2019.

I have seen code that only the programmer who writes it understands how it works. However, when one asks the programmer to explain what the code does, he or she would only say “Only God knows that”.

That is why I would like to discuss some basic (but very powerful) principles that will make your life (and most of your collaborators’ lives) easier.

1. DRY – Don’t Repeat Yourself

You must try to maintain the behavior of the functionality of the system in a single piece of code.
On the other hand, when the DRY principle is not followed, this is known as WET solutions, which stands for either Write Everything Twice or We Enjoy Typing.
DRY programming is very useful, especially in big applications where the code is constantly maintained, changed and extended by a lot of programmers.

A common way to DRY up code is to wrap our duplicated logic with a function and replace all places it appears with function calls.

Example (with code repetition):

//flow A

let username = getUserName();
let email = getEmail();
let user = { username, email };
client.post(user).then(/*do stuff*/);
Enter fullscreen mode Exit fullscreen mode

//flow B
let username = getUserName();
let email = getEmail();
let user = { username, email };
client.get(user).then(/*do stuff*/);
Enter fullscreen mode Exit fullscreen mode

DRY Example:

function getUser(){
    return {
        user:getUserName();
        email:getEmail();
    }
}
//flow A
client.post(getUser()).then(/*do stuff*/ );
//flow B
client.get(getUser()).then(/*do stuff*/);

Enter fullscreen mode Exit fullscreen mode

2. KISS – Keep It Simple Stupid

The simpler your code is, the simpler it will be to maintain it in the future. This will be greatly appreciated by anyone else that needs to examine your code in the future.

Keeping it simple surprisingly hard. Usually when someone tries to over-engineer a solution to a problem. For example, an Architect suggests creating a Microservice framework for a simple website.

3. YAGNI – You Aren’t Gonna Need It

Sometimes, as developers, we try to think way ahead, into the future of the project, coding some extra features “just in case we need them” or thinking“we will eventually need them”. Just one word: Wrong! You didn’t need it, you don’t need it and in most of the cases… “You Aren’t Gonna Need It”.

A step brother of KISS. Part of keeping it simple is not adding modules, frameworks and dependencies we don’t actually need.

💖 💪 🙅 🚩
sandipmavani
Sandip Mavani

Posted on January 10, 2019

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

Sign up to receive the latest update from our blog.

Related