Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
skonteam9628y@crisz that's not a world where I want my code executed so I'll stick to 5 and 100 .
-
Yonah1498y@KeyWeeUsr in this case we do not care about decimals and +-1 precision is good enough.
-
jimmeh10498yI think the beauty here is that they use 5 and 100 as variables to change them easily, but the function name is "getFIVEpercentofvalue".
-
Cube18929268y@DeveloperACE That's when you directly use "raw" numbers in your code instead of assigning them to a variable first which would theoretically make said code easier to understand and maintain/modify.
-
Cube18929268yMaybe someone was using a code analyze tool and didn't bother with surpressing the warnings. CheckStyle with default set of rules freaks out when it sees any magic numbers.
-
Meh, script kiddie stuff. Let's enterprise-grade this shit:
TheNumberFiveFactory fiveFac = TheNumberFiveFactory.getInstanceOrCreate();
TheNumberOneHundredFactory oneHundredFac = TheNumberOneHundredFactory.getInstanceOrCreate(NumberFactoryOption.DEFAULT);
If (fiveFac == null || oneHundredFac == null)
throw new NumberFactoryNotFoundException();
Five five = fiveFac.getNumWrapped();
OneHundred obeHundred = oneHundredFac.createNumWrapped();
if (!five.equals(5) || !oneHundred.equals(100))
throw new NumberResolutionFailure();
return five.visit(oneHundred, NumberOps.getOp("division")).getValue(); -
@benhongh it hurts my eyes so much! LetSUseLongerNamesForEveryRandomPartOfAnyDamnLanguageForNoSaneReason-much.
-
Yonah1498y@KeyWeeUsr In Java Spring if a class name is less than 20 characters it is not a proper class :)
But I can't see a problem with long names, better than int a, b; -
@Yonah as Ben said ^^ Also, not that I'm actually for minified code, but if the class name is twice+ longer than its value, there's probably something wrong. And who should read that later? Write comment(s), not unnecessary long class/variable names. :P
-
Leya17718yIf you write it like this at least make it have more use cases and define it like float getPercentOfValue(float percent, float number)
-
MaccaMc5528yGuys chill. It's just incase the value of 5 or 100 changes at some point in the future. Gawd...
When someone really really doesn't like "magic numbers" in their code.
undefined