Question

Im working on a GUI. I am getting magic numbers for setSize values. since magic numbers are bad practice, How can i get rid of the magic numbers in size? should i assign a variable to each of them?

setSize(250x400)

so that it will be like setSize(x,y). what is the best way to overcome this? should i do this or is there another better way? what if there are many sizes, this will be useless as i cannot be assigning for each and every one.

Was it helpful?

Solution

You should calculate the size according to user's screen size when designing a GUI. Using magic numbers here would work well for a fraction of users, but would be terrible for some.

For example, you first get the user screen width and height and then you decide what fraction of screen size is needed for each element. Then you set the size using a fraction of screen width and height.

This would be the best practice because any user with any screen size would experience something the same!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top