Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18814
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Shorter is not always better |
| Date | 2021-11-23 12:17 +0100 |
| Message-ID | <j040tpFhhfuU1@mid.individual.net> (permalink) |
| References | <j03vf8Fh95uU1@mid.individual.net> |
On 23/11/2021 11.52, Arno Welzel wrote:
> An simplified example from a real project:
>
> if (!($this->action[$key] ?? false)) {
>
> However to understand this you must know what the ?? operator means and
> note the negation using ! in the beginning.
What if you don't know about === then the null check below looks strange
and you would think it has a bug.
There will always be something you don't know about, but people tend to
learn.
> I would prefer a longer but easier to understand solution like this:
>
> if (!isset($this->statusActions[$key])
> || null === $this->statusActions[$key]
> ) {
>
> Any thoughts on this?
I do prefer the short one, but then I'm used to that kind of code and
the code analyzer at work do complain when you have a lot of if
statements with unnecessary and/or operators.
There can also be code execution gains with the short compact code
compared to do the "traditional" way. There been times where I have
managed to make the code execution 1/100 of the original time using the
shorter compact code.
In the end it's about the head coders taste and maybe company coding
standard that will dictate when you write, it's like some people like
oop while others don't, it don't make the whole world what you pick, as
long as the program works in the end in a safe way. Just look at the
source code for mplayer, the rows are extreme short as the head coder
max screen resolution was 800x600 and wanted to see all lines without
row-wrapping.
--
//Aho
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