Why Magic numbers are bad? [JAVA TIP]

Hey guys, today I'd like to share a tip about "How to avoid magic numbers in your code".
Let's look at the first code snippet:
float getScaledPageWidth(float zoomRation) {

return zoomRation * 210;

}
And here is the updated version:
static final float A4_PAGE_WIDTH = 210;

 

float getScaledPageWidth(float zoomRation) {

return zoomRation * A4_PAGE_WIDTH;

}
Do you know what the differences? Can you guess what was improved?

And remember to share with your friends if you want them know tip too. I bet they will be thankful you.

Comments

Popular posts from this blog

Concept of OOPS

[JAVA Assignment] Write a program to allow user to enter 10 Integers and writes the smallest number

Having problems!!!!!