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
Why non-typed languages are still allowed in production systems is wild — idk why anyone doesn’t want that layer of safety / readability
Replying to @gdb
Better yet, build it out of the language
2
Replying to @gdb
Evaluating the length is much more computational work, for no reason.
Replying to @gdb
I hate it when people do this in C/C++.
1
Replying to @gdb
There’s good complexity and there’s bad complexity. Saving 10 keystrokes for 5x higher cognitive load is the bad kind.
12
Replying to @gdb
I sometimes do `if len(mylist):`, which at least is enough to identify at a glance what kind of truthiness is being relied on.
1
3
Replying to @gdb
In the bible it says if you bool yourself you will get hairy hands.
Replying to @gdb
It's at least not convention in python to do none checks like this. "if(mylist)" instead of "if(mylist!==undefined)" is the number one bug in our typescript codebase. The issue is also not the missing typing, but those boolean conversion rules.
2
Replying to @gdb
Actually more keystrokes are needed: if mylist is not None and len(mylist) > 0:
11
Replying to @gdb
A nice thing about the explicit way is that it doesn’t fail with pandas series. “ValueError: The truth value of a Series is ambiguous …”