2 ms·
>Both are inferior to "$ymd" Nope. $ymd encodes information about the formatting of the date that could just be an implementation detail (and might change, e.g
by coldtea 9y ago
>Both are inferior to "$ymd"
Nope. $ymd encodes information about the formatting of the date that could just be an implementation detail (and might change, e.g. need to have the hour/minute too later, or have the month first, or be encoded in a different timezone etc). Whereas that it's the "current date" is a business predicate, and more relevant.
>addExpireAt(DateGlobal::SECONDS_IN_A_DAY);
Who would ever need to search for that? You'd search for "Expire"
I might search for all kinds of things. A searchable name is better. It's also a good way to write the constant, whether you search or not.
>Now, this is how you create the good old copypasta.
Depends on how many options there are and how crucial is what they do. Two clearly defined functions can be better than an "abstract" function and two instances.
>should be "Avoid double-negative conditionals"
No, it's negative conditionals alright. The example to be avoided is: "isDOMNodeNotPresent" -- where's the double-negative?
>Except at some point you will need setModel() to fail for some arguments, e.g. setModel('Trabant'), and you will end up with some methods returning $this and some not. This is not going to be a "clean code" by any measure.
You can trivially use an Exception to signal that. And in other languages, an Optional/Maybe etc type.
- 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.