9

private static final int TEN = 10;
private static final double THOUSAND = 1000.0D;

[a copy-paste from our repo]

Comments
  • 10
    This is like when someone uses a hexadecimal color value as the name for the variable of the very same hexadecimal color value. 🙃
  • 5
    Arguably

    Return TEN * THOUSAND

    Sometimes reads nices than

    Return 10000;

    Though I prefer

    Return 10_000;
    Where supported...

    Though this is common for working with memory values like
    BYTE = 8
    KILOBYTE = 1024 * BYTE
    MEGABYTE = 1024 * KILOBYTE

    and so on...

    I can sometimes see the appeal then
  • 2
    @Hazarth I agree with BYTE, KB, MB constants - they all make sense to a person and no sense to a machine.

    But why tf do a TEN, THOUSAND and similar ones, which add absolutely no meaning to a developer and no meaning to a machine???

    Choose meaningful names, not crap like this...
  • 5
    @netikras the cherry on top would be if there also were comments like this:

    // ten
    // thousand
  • 3
    @netikras At least it isn’t int INT_TEN and double DOUBLE_THOUSAND?
  • 4
    private static final int A_DOZEN = 12;
    private static final int A_GROSS = 144;

    When you want to write literature but are friced to write code...
  • 4
    Ahw laaawrd thank you! I never get when people write 10000. Never know if they mean ten thousand or hundred hundred.
  • 1
    @ScriptCoded not sure if joke or sarcasm 😄

    Anyway, it’s just for better readability because it’s easier to see the number of zeros. That’s why there are groups and group separators in natural languages.
    _ is the programming language specific, natural language agnostic group separator. 🙂
  • 1
    @Hazarth No, please don't use SI-Prefixes when you mean binary prefixes. Especially when you use bit as the base unit. 1 MB=1000 KB=1000000 B. 1 MiB = 1024 KiB = 1048576 B

    For 10000UL you can use 10UL*1000
  • 1
  • 2
    ... for units or fixed numerals. yes.

    But for fucks sake please don't create a fucking const for everything that might be possible used.

    I still have vivid nightmares and pretty brut gore fantasies about classes like

    interface / class constants {
    public const HTTP_OK = 200;
    public const PI = 3.14;
    ....
    public const API_XY_CALLBACK='...';
    ...
    }
    Roughly 1_000 to 10_000 entries...

    Devs (different companies even...) then proudly saying it's a great idea cause "we don't use magic / strings numbers here"...

    Yeah. But one evil replaced by a ctulhu cluster fuck isn't better -.
  • 2
    @IntrusionCM can relate. One colleague just created a god class with the name Constants and started to put everything into there as static constants. Even stuff that is only used once.

    I find it really dumb and rather have my constants in places where they are actually used. And can be private there. Or just literals instead of values stored in named constants that don’t add any meaning to those values.
  • 1
    @Lensflare Yes...

    Sit it up to be "package" or class relevant.

    Anything that doesn't end up like a waste dump and is superb for creating merge conflicts.
Add Comment