Express Intent to naming things

Bhima Werkudara
Jul 10, 2017 · 1 min read

the one of important things in programming is naming things. Naming a class, a method or a variable. Are you agree the hardest part in programming is naming the variables?

Ok, lets go to the point. I want to make a triangle class in java.

public class MyClass {   public int b;
public int h;
public double result() {
return ((b * h)/2);
}
}

Is the class looks good to you?

Let me explain to you. MyClass is a triangle model, it has b for base and h for height. so, what’s method result for? It is a method to calculate area of the triangle.

Class MyClass is bad example in write a class. If there is no explanation, people couldn’t understand.

The good idea to naming class is express intent. All of line inside the class should be readable. We should naming the class, variables and method with proper name, so that people can understand what the meaning of that code easily.

public class Triangle {   public int base;
public int height;
public double area() {
return ((base * height)/2);
}
}

Looks better, huh?
Don’t forget to make your code clean and clear.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade