I understand that it is better not to use negatives as much as possible after reading the readable code, but
I think there are situations where you have no choice but to use it.
In that case, for example, which of the following is better for Python?
if not something()
if doesNotHaveSomething()
Or, if there is another way to write it, please let me know
python python3
Readable code claims like this
For the latter, it is also stated that negation may be easier to read.
if not something()
if doesNotHaveSomething()
In the readable code, you should think about turning over then and else to erase the former not
, but if you can't do that, you should use the former.
In the latter case, it's hard to think about what happens when doesNotHaveSomething()
returns false
.This is why "do not use negatives in your name."
"""I can't help but use negation"" = ""It's readable to use negation."
"
In general, "Do not use negatives" does not mean that you should not use negative operators, but it is about method names, etc.
"If there is a negative element, the cause may be ""denial of negation"" or the loss of consistency."
You don't have to prepare a method like doesNotHaveSomething()
, but not hasSomething()
, right?
(Whether to follow this or not is a matter of subjectivity.)
547 Who developed the "avformat-59.dll" that comes with FFmpeg?
549 PHP ssh2_scp_send fails to send files as intended
542 Unable to install versioned in Google Colab
534 Uncaught (inpromise) Error on Electron: An object could not be cloned
547 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.