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
-
This is like when someone uses a hexadecimal color value as the name for the variable of the very same hexadecimal color value. 🙃
-
Hazarth95193yArguably
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 -
@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... -
-
Ahw laaawrd thank you! I never get when people write 10000. Never know if they mean ten thousand or hundred hundred.
-
@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. 🙂 -
@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 -
... 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 -. -
@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. -
@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.
private static final int TEN = 10;
private static final double THOUSAND = 1000.0D;
[a copy-paste from our repo]
rant
clean code done wrong