Navigating the Readability Conundrum: Code Quality > Styling

Jeremy Tong
2 min readDec 4, 2023

--

Imagine you’re in a new codebase, and you’re greeted by a sea of these critters

In the intricate landscape of coding, a common pitfall emerges — the indiscriminate use of decimals in code styling and constants. This practice often stems from the desire to wrangle front-end code to perfection, a pursuit that can inadvertently compromise code quality and readability.

Sacrificing exact styling or precision in favor of code quality is a worthwhile trade-off. As developers gain experience, they can gradually hone their abilities to reintroduce precision but only when the code meets the prerequisites for such refinement.

Code Quality Trumps UI:

The allure of perfecting the user interface (UI) can sometimes overshadow the importance of writing clean, readable code. It’s crucial to emphasize that code quality should always take precedence over achieving pixel-perfect styling.

Sacrificing Styling Precision for Readability:

Emphasizing the use of whole numbers and relative units, even if they sacrifice some styling precision, lays the foundation for a codebase that is accessible and maintainable.

Consider the following CSS snippet:

.container {
width: 50.5%;
margin-left: 2.3em;
padding: 1.2rem;
}

While it may seem innocuous to use decimal values for styling properties such as width, margin, or padding, it can introduce unnecessary complexity. Decimals lack semantic meaning in this context and may leave developers scratching their heads, questioning the significance of values like 2.3em.

.container {
width: 50%;
margin-left: 2em;
padding: 1rem;
}

Using whole numbers or relative units, like percentages, can enhance readability and make the styling intentions clearer. Futhermore, it may mislead a developer from using proper patterns of styling, such as relative position with flexbox.

Constants with Decimals:

When employing decimals as constants without a clear rationale, it can obscure the purpose of the constant and make the code less self-explanatory.

TAX_RATE = 0.087

Here, the decimal 0.087 represents a tax rate, but without context, its significance may not be immediately apparent. Instead, consider using integers or more expressive variable names to improve code readability.

TAX_RATE = 8.7 / 100 

Conclusion:

As developers gain experience, they can gradually reintroduce precision without compromising code quality. The trade-off is not a permanent compromise but a strategic decision that lays the groundwork for future success. Novice developers are encouraged to prioritize understanding and writing clean code, deferring exact precision until their coding skills mature.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Jeremy Tong
Jeremy Tong

Written by Jeremy Tong

Startup-Focused Software Developer

No responses yet

Write a response