Enable assert_without_msg DScanner check#5578
Conversation
|
Thanks for your pull request, @wilzbach! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
|
Hmmm, is this a standard we want to apply to every assert? Ping @andralex. What's your opinion on this? |
|
A message on static assert is nice but not always required - e.g. it often refers to an implementation matter that is obvious from context. I'm not strong pro or con. FWIW C++ does require a message, which people often provide as |
|
A message on each non-static assert would be nice to have though. |
|
I think having to write |
|
IMHO, if it's clear from the assertion's condition what is being checked, then a message is pointless. e.g. what are you going to do with Now, if the message can make it unnecessary to look at the code, then great (function pre-conditions could be a good example of this), and it is certainly the case sometimes that the condition needs extra explanation, in which case a message it definitely warranted. But IMHO, an assertion message is often pointless. So, I don't think that requiring that all assertions have messages makes a lot of sense. |
I think that that's an example of one where a message helps clarify the situation and potentially eliminates the need to look at the code, so I agree that it makes sense. I just don't agree that it's always an improvement to have a message. Sometimes, it's just redundant, or you'd have to look at the code to understand the issue anyway, so the message doesn't help. |
That's a fair point, but the bigger picture question is whether enforcing this rule (and fixing the instances it identifies) will have a net positive impact in the end. Some redundant assertion messages may be a bit annoying, but being 100% sure that a D user will never again see an "assertion failed" message inside Phobos code with no further explanation sounds like a goal worth pursuing. |
|
A bug in favor of this change: |
|
@jmdavis I think all things considered we would gain more by going forward with this, what do you think? |
|
What's the holdup on this? There is never a good reason to not include an assert message; it's the difference between getting an error message immediately on the command line and having to open up the code to the error location to figure out what went wrong. IMO this is a no-brainer that affects basic usability. |
|
ping @wilzbach |
f3f2169 to
1ee2dd3
Compare
from the assert_without_msg blacklist
1ee2dd3 to
2591b61
Compare
As newer DScanner versions contain this check (at least the |
dlang-community/D-Scanner#495 is now on the
phobosbranch of DScanner.Assert messages are very helpful to a user and we should try our best to avoid things like
or
See also the NG thread with this idea or dlang-community/D-Scanner#495
FWIW the blacklist might look long, but (1) the opposite is long as well and (2) we should try to improve the status quo - module per module (many modules only contain a few
assert(0);CC @CyberShadow @andralex