news.volyx.in

Please put units in names (ruudvanasseldonk.com)

1284 points by todsacerdoti · 1639 days ago · 594 comments on HN

Article summary

The article discusses the importance of including units in variable and function names to improve code readability. It provides examples of how omitting units can lead to ambiguity and errors, and suggests using strong types or putting units in names as solutions. The article also applies this advice to various areas such as API design, metric names, and configuration files. By including units, developers can make their code more self-explanatory and easier to understand.

Main themes

  • Code Readability
  • Unit Specification
  • API Design
  • Strong Types
  • Code Maintainability

What commenters say

  • Using units in variable and function names is essential for code readability and maintainability. Some argue that requiring explicit unit specification can lead to verbose code, but others see it as a necessary trade-off for clarity. Including units in method names can help avoid misunderstandings and errors, especially when working with different units of measurement. Others propose using strong types, such as timedelta, to eliminate ambiguity. There is disagreement on whether using IDE hints or other tools can adequately address the issue of unit specification. Some suggest that using standard units, such as SI units, can simplify the problem, while others argue that this approach may not always be practical.
  • themes": [