Skip to content

Conversation

@bemoody
Copy link
Collaborator

@bemoody bemoody commented Mar 1, 2022

If a parameter X is documented as having a boolean value, it should be treated (in duck-typing style) as true if bool(X) is true, or false if bool(X) is false.

Writing "if X is True" is almost always a bad idea: it suggests to the reader that "X is True" and "X is False" are the only possibilities, when in fact there is no such guarantee.

(In some cases it might make sense to explicitly check argument types to catch programming errors - but in most cases this feels like an overcomplication, and even then it's a bad idea to write "if X is True" because the permitted argument types might change in the future.)

To wit: rdrecord("foo", physical=0) would do what you expect; rdrecord("foo", physical=1) would crash. rdrecord("foo", smooth_frames=1) would do what you expect; rdrecord("foo", smooth_frames=0) would crash.

Benjamin Moody added 3 commits March 1, 2022 12:39
Writing "if X is True" is almost always a mistake.
Writing "if X is True" is almost always a mistake.
Writing "if X is True" is almost always a mistake.

This change allows rdrecord to be called with "physical=1"
("physical=0" would work previously, but "physical=1" wouldn't) or
with "smooth_frames=0" ("smooth_frames=1" would work previously, but
"smooth_frames=0" wouldn't.)
@tompollard
Copy link
Member

looks good, thanks!

@tompollard tompollard merged commit 7d30c20 into master Mar 3, 2022
@tompollard tompollard deleted the booleans branch March 3, 2022 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants