Timeline for Using Null/None/Nil vs empty data types
Current License: CC BY-SA 4.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 9, 2019 at 20:16 | comment | added | JimmyJames |
I guess if you want to be sure the reference is to None you need to use is but I still think it should be the exception that you are checking for identity, not the rule.
|
|
| Aug 9, 2019 at 19:38 | comment | added | JimmyJames |
If it's crucial to the algorithm that the reference is None then you should be checking for None. I think something != None is more clear way of doing that. But I disagree that building logic around truthiness is necessarily wrong. Overriding __bool__ is a useful feature.
|
|
| Aug 9, 2019 at 19:29 | comment | added | amon | @JimmyJames None is supposed to be a singleton, and checking for identity is the only reasonable approach. As explained in my answer, truthiness can be misleading. Personally, I'm tired of bugs where you cannot set a parameter to zero or the empty string. | |
| Aug 9, 2019 at 19:24 | comment | added | JimmyJames |
I'm not sure I buy that checking explicitly for None is necessarily better. Building logic around object identity seems like an error to me. If you instead build around truthiness, you can use None or something more sophisticated. If you hard-code None in your checks, it's a lot less flexible.
|
|
| Aug 9, 2019 at 19:10 | vote | accept | Michael M | ||
| Aug 9, 2019 at 18:08 | history | answered | amon | CC BY-SA 4.0 |