-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Not Applicable
-
Storage Engines
-
3
-
StorEng - Defined Pipeline
List of constants in question:
- WT_MILLION_LITERAL
- WT_THOUSAND
- WT_MILLION
- WT_BILLION
These constants do not add value to the code because they lack descriptive context about their usage, making the code less readable and harder to understand and maintain. Replacing 1000 with WT_THOUSAND does not clarify why this constant is significant or why the value is 1000. It merely abstracts the literal number into a different but equally vague form.
For example, WT_THOUSAND is used to convert seconds to milliseconds. However, its usage is not immediately intuitive. To grasp its purpose, a developer must first interpret WT_THOUSAND, deduce that it represents 1000, and then rely on the surrounding context to infer why this specific value is relevant. A more descriptive constant like WT_MSEC_IN_SEC would directly convey its meaning, eliminating any ambiguity.
Expected Outcome of This Ticket:
All (or the majority) of instances where these constants are used will be replaced with more descriptive names that better describe their specific purpose.
- Time Unit Conversions:
- Replace WT_THOUSAND with WT_MSEC_IN_SEC (milliseconds in a second), WT_NSEC_IN_USEC (nanoseconds in a microsecond), etc.
- Replace WT_MILLION with WT_USEC_IN_SEC (microseconds in a second) or WT_NSEC_IN_MSEC (nanoseconds in a millisecond).
- Replace WT_BILLION with WT_NSEC_IN_SEC (nanoseconds in a second).
- Other Uses:
- For use cases such as counting elements, iterations, or other domain-specific values, replace the constants with appropriately named alternatives that clearly describe their purpose (e.g., WT_ROWS_PER_BATCH, WT_ITEMS_PER_PAGE).
- No replacement:
- If a literal number constant legitimately can be used in the code, then it's also fine to use one of these constants.
- Exceptional Cases:
- If replacing a constant is not feasible for a specific use case, it should be reviewed and considered individually to determine whether the current usage is justified or if other improvements can be made.