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