Unpopular opinion: don't rely on implicit truthy constructs in your language, and instead always convert to bool yourself. For example, in Python rather than "if mylist:", do "if len(mylist) > 0:". An example of trading more keystrokes for less cognitive burden for readers.

Apr 14, 2022 · 5:44 PM UTC

19
24
6
419
Replying to @gdb
In a real context, the list should have a much more meaningful name - ie "devices". Then, if devices: ... is naturally informative and still works on NULL, which is a very common possibility.
Replying to @gdb
Disagree, as a developer and advocated to use PEP8 style guide, you should learn to name variables with consistent and coherent names and use type hints to improve readability. I would agree if you would have said... don't use "if not not x" just for perfomance purposes.
6
Replying to @gdb
I wish this was the popular opinion.
1
Replying to @gdb
I do agree that we should trade more keystrokes for less commutative burden. I don’t agree that this is a good example.
1
Replying to @gdb
"if mylist:" requires no additional cognitive load from people familiar with Python. In general: Use comments as extensively as necessary to make the code clear, but *never* compromise on the code itself.
3
11
Replying to @gdb
👍 especially since some people they review the code may not be python experts
Replying to @gdb
So, every time it test for length it will call the length function? What if just store it in a more descriptive variable and test without having to call again a function?