JAVA, Programmimg Languages, Tips

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s