≈ volna.computerSince February 2026
← My notes

Put the unit in the timeout

A timeout named timeout leaves its unit to whoever reads the surrounding code. Calling it timeout_ms makes one part of the contract visible at every call site. That matters when a value travels through a settings form, a configuration file, and a library call.

Imagine a report generator whose settings screen accepts a timeout in seconds. A user enters 30. The server passes that number to a client library expecting milliseconds. Everything has a plausible type: the form contains a number, the saved configuration contains a number, and the library accepts a number. The report now gets 30 milliseconds to finish.

I would keep seconds in the form and name that field timeout_seconds in the request. At the library boundary, one adapter converts it to milliseconds and passes a variable named timeout_ms. Other callers use the adapter. Keeping the conversion in one place makes it possible to inspect the whole translation without tracing every caller.

The conversion also needs a policy for values the destination cannot represent. Suppose the form allows fractional seconds but the library accepts only whole milliseconds. The adapter must decide whether to round or reject excessive precision. Validate the supported range before passing the result onward, including the upper limit of the receiving library.

In this hypothetical library, zero disables the timeout. In the product, a user might reasonably read zero seconds as an immediate deadline. I would offer a separate "No time limit" choice and accept only positive durations in the numeric field. The adapter can translate that explicit choice to the library's zero. A missing configuration value can still mean "use the default" without becoming another spelling of unlimited.

For a review, trace 1.5 seconds from the form to the library and check that the library receives 1,500 milliseconds. Also try an omitted value, the unlimited choice, a negative number, and a value above the supported range. Check the value passed to the dependency, since a test of the conversion helper alone can miss a caller that bypasses it. The error shown for an invalid value should use seconds, the unit the user entered.