Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use a meaningful computed bound instead of an arbitrary magic number
When you need an extreme value (scroll to bottom, clamp, max), use the real computed bound rather than a large arbitrary number. It self-documents intent and stays correct regardless of content size.
Bad example
| 1 | // scroll to the bottom |
| 2 | window.scrollTo(0, 9999); |
Explanation (EN)
9999 is an arbitrary guess at the bottom; it breaks for taller content and hides intent. The reader has to infer what 9999 means.
Objašnjenje (HR)
9999 je proizvoljna pretpostavka dna; puca za visi sadrzaj i skriva namjeru. Citatelj mora pogadati sto 9999 znaci.
Good example
| 1 | // scroll to the bottom |
| 2 | window.scrollTo(0, document.documentElement.scrollHeight); |
Explanation (EN)
scrollHeight is the actual bottom, so it is correct for any content height and reads as the intent itself.
Objašnjenje (HR)
scrollHeight je stvarno dno, pa je ispravan za bilo koju visinu sadrzaja i cita se kao sama namjera.