September 4th, 2024

Explicit is better than implicit

The article highlights that explicit coding enhances readability and maintainability, reduces confusion, and improves collaboration by clearly defining variables and access controls, ultimately leading to better code quality.

Read original articleLink Icon
Explicit is better than implicit

The article emphasizes the importance of explicitness in coding, arguing that clear and well-defined code enhances readability and maintainability. The author, Trevor Lasn, illustrates how implicit coding can lead to confusion and increased difficulty in understanding code, particularly when hidden details are not clearly defined. For instance, using a hard-coded value like "10" without explanation can leave future developers puzzled about its purpose. In contrast, defining variables explicitly, such as using a "bonus" variable, clarifies the code's intent. The article also discusses access control in systems, highlighting how implicit permissions can create ambiguity. By using an explicit mapping of roles and permissions, developers can avoid confusion and make the code easier to manage. Lasn concludes that prioritizing explicitness over conciseness leads to better code quality, as it allows developers to understand the code's intentions more easily, facilitating collaboration and future updates.

- Explicit coding improves readability and maintainability.

- Implicit details can lead to confusion and increased difficulty in understanding code.

- Clear variable definitions enhance code clarity and intent.

- Explicit role and permission mappings prevent ambiguity in access control.

- Prioritizing explicitness fosters better collaboration among developers.

Link Icon 3 comments
By @ddejohn - 8 months
This article has virtually nothing to do with implicit vs explicit code. The examples are just poorly written and poorly documented code. And even the "improvements" aren't that great. Why does `grantAccess` return permissions the user role already has?
By @sakjur - 8 months
In both ACL examples, if I send in a user that has the role “adnim” it’ll quietly and happily treat that as the same as “guest”.

You can certainly make that design decision, but I think my take of “explicit is better than implicit” is to let the server logs complain about invalid roles (and then rejecting access, even if a guest would’ve had access).

By @rednafi - 8 months
Seems like slop.