143
Yonah
8y

When someone really really doesn't like "magic numbers" in their code.

Comments
  • 4
    this is so ocd.
  • 12
    waste of 2 lines :/
  • 3
    "Magic numbers"?
  • 26
    This is so wtf... it returns INT omg! -_-
  • 7
    @maximizer not only, he allocated two useless memory areas
  • 13
    What if tomorrow five and one hundred change? Let's not risk
  • 2
    that person doesn't like floating-point
  • 3
    @crisz that's not a world where I want my code executed so I'll stick to 5 and 100 .
  • 1
    @KeyWeeUsr in this case we do not care about decimals and +-1 precision is good enough.
  • 2
    why? just why?
  • 2
    @OiYouYeahYou in case the requirements change and five must now be redefined as 7...
  • 4
    I think the beauty here is that they use 5 and 100 as variables to change them easily, but the function name is "getFIVEpercentofvalue".
  • 3
    @Yonah Except in this case the precision is +/- 5 because of the integer division...
  • 2
    @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.
  • 2
    Maybe 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.
  • 1
  • 2
    Someone harvesting them commits.
  • 6
    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();
  • 0
    @benhongh it hurts my eyes so much! LetSUseLongerNamesForEveryRandomPartOfAnyDamnLanguageForNoSaneReason-much.
  • 1
    @KeyWeeUsr well that's what you do in Java and why I have been avoiding it.
  • 0
    @KeyWeeUsr yeah a b c is way better
  • 0
    @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;
  • 1
    @Yonah it's not about naming, is about needless over abstractions.
  • 0
    @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
  • 1
    If you write it like this at least make it have more use cases and define it like float getPercentOfValue(float percent, float number)
  • 2
    Guys chill. It's just incase the value of 5 or 100 changes at some point in the future. Gawd...
  • 1
    @MaccaMc hahahaha :D
  • 0
    Times by 0.95
Add Comment