Watching the examples you provided, Following:
operator++ (postfix / prefix)
string.empty() vs string == ""
Doesn't seem like good examples, as they compare operations other than functionality . Consequently, one does not better ignore their semantic differences.
In contrast, the following examples:
vector.empty() vs vector.size() == 0
enum erate { on , off } vs. boolean on=true ; off=false
Absolutely reasonable.
vector.empty() is preferred if the context of its use is only to determine if the vector is empty. By reducing risk, it is condescending (which I do not ): it comes down to common sense. Why ask the size of a vector only if you want to know if it is empty? It is like asking someone how much money they have in their wallet when you just want to find out if they have enough cash for Cox.
Regarding enum erate { on , off } vs boolean on=true ; off=false , ask yourself: how likely is it that you can add another value to the enumeration in the future? It seems reasonable that enum erate { on , off , indeterminate } `(or some option) may be required, so the answer may be yes. Otherwise, a simple Boolean is sufficient.
This brings me to the core of your question: what seems to exist if there is some kind of deterministic / algorithmic approach to this or that solution of such issues or their relevance? I answer that until the Turing Machines can pass the Turing Test , I would say no. This is the reason why people should develop software.
source share