Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18816
| Path | csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
| Newsgroups | comp.lang.php |
| Subject | Re: Shorter is not always better |
| Date | Tue, 23 Nov 2021 23:48:28 +0000 |
| Organization | A noiseless patient Spider |
| Lines | 49 |
| Message-ID | <87r1b6e8mr.fsf@bsb.me.uk> (permalink) |
| References | <j03vf8Fh95uU1@mid.individual.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | reader02.eternal-september.org; posting-host="ab60dde8ea72ad07e673c0b27c8130b3"; logging-data="13864"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sQF90huVzsR6Lfbb75sLvzZTGYgedgT0=" |
| Cancel-Lock | sha1:uoX9O32iuEqzKhkhP7NXn7EoH7g= sha1:luKcSbqY0GogsVESAZKW9i8YaxY= |
| X-BSB-Auth | 1.bc869a9e85cc8ca0f9c2.20211123234828GMT.87r1b6e8mr.fsf@bsb.me.uk |
| Xref | csiph.com comp.lang.php:18816 |
Show key headers only | View raw
Arno Welzel <usenet@arnowelzel.de> writes:
> An simplified example from a real project:
>
> if (!($this->action[$key] ?? false)) {
>
> What it means:
>
> 1) $this->action[$key] ?? false
>
> This return $this->action[$key] if $this->action[$key] exists and is not
> null or "false".
>
> 2) !( .... )
>
> Will negate the result - so the condition is true if $this->action[$key]
> does not exist or is null.
>
> However to understand this you must know what the ?? operator means and
> note the negation using ! in the beginning.
>
> When you did not create this code in the first place or try to find a
> bug expressions like this are not really helpful.
>
> I would prefer a longer but easier to understand solution like this:
>
> if (!isset($this->statusActions[$key])
> || null === $this->statusActions[$key]
> ) {
s/statusActions/action/g
>
> Any thoughts on this?
They are not quite the same as your longer version ignores "falsey"
values other than null. Taking those into account:
if (!isset($this->action[$key]) || !$this->action[$key]) { ...
but then I would just prefer
if (@!$this->action[$key]) { ...
But as for the original, there is something to be said for code that
takes a moment to grok. The real problem is code so obviously correct
that the reader misses the error! Having to work out what a line means
is no bad thing when debugging someone else's code.
--
Ben.
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Shorter is not always better Arno Welzel <usenet@arnowelzel.de> - 2021-11-23 11:52 +0100
Re: Shorter is not always better "J.O. Aho" <user@example.net> - 2021-11-23 12:17 +0100
Re: Shorter is not always better Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2021-11-24 09:57 +0000
Re: Shorter is not always better "J.O. Aho" <user@example.net> - 2021-11-24 15:53 +0100
Re: Shorter is not always better Jerry Stuckle <jstucklex@attglobal.net> - 2021-11-23 18:42 -0500
Re: Shorter is not always better Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-11-23 23:48 +0000
Re: Shorter is not always better See Kes Seda Hetkel Siia Kirjutab <he1983912@gmail.com> - 2022-06-30 19:21 -0700
Re: Shorter is not always better Stan Weiss <srweiss@erols.com> - 2022-07-01 01:05 -0400
Re: Shorter is not always better Allodoxaphobia <trepidation@example.net> - 2022-07-01 12:18 +0000
Re: Shorter is not always better Stan Weiss <srweiss@erols.com> - 2022-07-01 09:08 -0400
Re: Shorter is not always better Mateusz Viste <mateusz@xyz.invalid> - 2022-07-01 17:13 +0200
csiph-web