Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid comparison against nullptr, instead use it as boolean identity. #2168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hzeller
Copy link
Collaborator

@hzeller hzeller commented Apr 20, 2024

Readability improvement.

We never use pointers as an artifact of a low-level memory implementation, we always use it in the context of things that can exist or not.

For these, comparing against nullptr uses a low-level technical aspect about the implementation, but not what we mean.

Using the boolean evaluation is more expressive as it reads more naturally like an existence check if (thing) thing->dosomething()

C/C++ gives us the improved expressiveness, let's use it.

@hzeller hzeller requested a review from fangism April 20, 2024 23:50
@hzeller hzeller force-pushed the feature-20240420-avoid-nullptr-comprarison branch from e85ebee to 6217ae4 Compare April 21, 2024 00:14
@hzeller
Copy link
Collaborator Author

hzeller commented Apr 21, 2024

Some low-level technicality purists might argue that that the underlying representation should always bleakly shine through. I'd argue that readability and expression of intent is much more important.

@hzeller hzeller force-pushed the feature-20240420-avoid-nullptr-comprarison branch from 6217ae4 to c4f19c5 Compare April 21, 2024 06:04
Readability improvement.

We never use pointers as an artifact of a low-level memory implementation,
we always use it in the context of things that can exist or not.

For these, comparing against nullptr uses a low-level technical aspect
about the implementation, but not what we _mean_.

Using the boolean evaluation is more expressive as it reads more
naturally like an existence check `if (thing) thing->dosomething()`

C/C++ gives us the improved expressiveness, let's use it.
@hzeller hzeller force-pushed the feature-20240420-avoid-nullptr-comprarison branch from c4f19c5 to 4f742ef Compare April 22, 2024 06:19
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.

None yet

2 participants