3 ms·
> Nope. Yep. The original "bad" case was meant to capture the fact that the formatting is YMD. The "good" example however is stuffing a string with an YMD for
by huhtenberg 9y ago
> Nope.
Yep.
The original "bad" case was meant to capture the fact that the formatting is YMD. The "good" example however is stuffing a string with an YMD formatted date in a generically-named variable.
> A searchable name is better.
Nobody argues with that. Point being that search'ability of named constants is not the principal reason for using them.
> Two clearly defined functions can be better.
Unless they substantially overlap in their code, in which case it's not better.
> No, it's negative conditionals alright.
"isDOMNodeNotPresent" is not a _conditional_.
> You can trivially use an Exception
Certainly. But for every dev who thinks that exception-based error handling is a good idea there will be two who don't. And that's even without getting into whether it will be a clean code.
- coldtea 9y ago>Unless they substantially overlap in their code, in which case it's not better. Depends. DRY is not an absolute rule. Sometimes the added abstraction to make something DRY makes it messier. >"isDOMNodeNotPresent" is not a _conditional_. Well, the if is assumed, no? What the author suggests is to avoid having what you check being negative -- so not only "if (!$isNotFoo)" but also "if ($isNotFoo)" is bad as well "if (!isFoo)" is clearer imo. >But for every dev who thinks that exception-based error handling is a good idea there will be two who don't. Some people don't like checked exceptions, but I don't think many have beef with exception based error handling.