New-ish coders have a tendency to add extra variables in order to solve a problem. Because these are often scratchpad variables, their names are often related to the primary variable of interest with little to distinguish their 'supporting role' purpose. The virgin reader is left wondering why has something (max) disappeared from view in the code; or has it?
- One line comment saves reader from wondering "What have we here?"
- One less variable at 'function scope'
size_t used appropriately
- 0th element initially is the maximum so far
- 'Greater than' triggers replacement (makes sense to me)
- Whitespace to aid clarity (style choices)
- No braces for single line bodies (style choices)
- No 'magic number' being
-1
- No concern about matching the datatype of the values being compared
- 'Greater than' triggers replacement (makes sense to me)
- Whitespace to aid clarity (style choices)
- No braces for single line bodies (style choices)