Client: Give function/member/constants name postfix based on unit, e.g. timeoutMsec, fileSizeBytes, secondsPerHour ...

Created on 19 Apr 2017  路  4Comments  路  Source: owncloud/client

good first issue technical debt

Most helpful comment

It is also nice to give conversion constants etc names with units of measure, rather than putting "magic numbers" in places. e.g. things like
secondsPerHour (instead of magic 3600)
bytesPerKilobyte (instead of magic 1000)
bytesPerKibibyte (instead of magic 1024) https://en.wikipedia.org/wiki/Kibibyte
and so on.
Then calculations can be read "naturally" because names are like:

estimatedHours = estimatedSeconds / secondsPerHour

All 4 comments

It is also nice to give conversion constants etc names with units of measure, rather than putting "magic numbers" in places. e.g. things like
secondsPerHour (instead of magic 3600)
bytesPerKilobyte (instead of magic 1000)
bytesPerKibibyte (instead of magic 1024) https://en.wikipedia.org/wiki/Kibibyte
and so on.
Then calculations can be read "naturally" because names are like:

estimatedHours = estimatedSeconds / secondsPerHour

Or better yet, encode it in the return type.
For time period, we should return std::chrono::milliseconds or std::chrono::seconds
Similarly, for For sizes, we could have an equivalent type for sizes.

Not only this documents exactly the unit in the function signature, but also check at compile time that we do the right conversion

Was this page helpful?
0 / 5 - 0 ratings