3 ms·
In this example the assert is less explanatory than a comment. Why do if (condition): ... else: assert(!condition) ... When yo
by kr0bat 3y ago
In this example the assert is less explanatory than a comment. Why do
if (condition):
...
else:
assert(!condition)
...
When you could instead
if (condition):
...
else: #if (condition)
...
Or otherwise explicitly comment the condition that was checked earlier. At least then if the comment is unchanged, whoever is touching your code will assume the comment is outdated, rather than assuming that you're asserting that x should be some undocumented magic number.