3 ms·
The scope of TFA is data modelling, where it advises to use more descriptive data values, such as enums or happenedAtTimestamp. However, personally I agree wit
by fifticon 1y ago
The scope of TFA is data modelling, where it advises to use more descriptive data values, such as enums or happenedAtTimestamp.
However, personally I agree with the advice, in another context: Function return types, and if-statements.
Often, some critical major situation or direction is communicated with returned booleans.
They will indicate something like 'did-optimizer-pass-succeed-or-run-to-completion-or-finish',
stuff like that.
And this will determine how the program proceeds next (retry, abort, continue, etc.)
A problem arises when multiple developers (maybe yourself, in 3 months) need to communicate about and understand this correctly.
Sometimes, that returned value will mean
'function-was-successful'.
Sometimes it means 'true if there were problems/issues'
(the way to this perspective, is when the function is 'checkForProblems'/verify/sanitycheck() ).
Another way to make confusion with this, is when multiple functions are available to plug in or proceed to call - and people assume they all agree on "true is OK, false is problems" or vice versa.
A third and maybe most important variant, is when 'the return value doesn't quite mean what you thought'.
- 'I thought it meant "a map has been allocated".'
- but it means 'a map exists' (but has not necesarily been allocated, if it was pre-existing).
All this can be attacked with two-value enums,
NO_CONVERSION_FAILED=0, YES_CONVERSION_WAS_SUCCESFUL=1 .
(and yes, I see the peril in putting 0 and 1 there, but any value will be dangerous..)
- 1718627440 1y agoThat's why you have coding style guides and documentation. Both choices are "correct", you just need to be consistent.