Consider a parameterless (edit: not necessarily) function that performs a single line of code, and is called only once in the program (though it is not impossible that it'll be needed again in the future).
It could perform a query, check some values, do something involving regex... anything obscure or "hacky".
The rationale behind this would be to avoid hardly-readable evaluations:
if (getCondition()) {
// do stuff
}
where getCondition()
is the one-line function.
My question is simply: is this a good practice? It seems alright to me but I don't know about the long term...
getCondition
? If it's as small and infrequently used as you say it is then giving it a name is not accomplishing anything. – Sep 13 '11 at 04:22getCondition()
could simply be a private method which separate the condition logic from the rest of the logic, e.g. for readability's sake. I don't think you can assume thatgetCondition()
must invariably depend on global state (let alone James Anderson's response that some things simple are global state without being wrong) – Flater Oct 27 '21 at 11:27