-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Negative property names should be discouraged #6131
Comments
Nowadays I even prefer |
I'm finding similar discrepancies in MudBlazor all the time. Maybe these should be identified for rename in the next major breaking change? As of using 'Is', 'Has', 'Can' ... in bool prop names - this is opinionated subject and intellisense to the rescue but if I'd had to vote, I'd say to keep them to avoid ambiguity. For example IsSet prop reads differently to me than just Set. Also I'm coming from WPF background (and now MAUI) and they both follow that convention and I'm just used to it. The problem here is that there is no consequence in naming. |
You may want to look at the next milestone, the is basically the opposite of your proposal already on it. |
Could you please share the link where I can find the next milestone plans? I've found https://github.com/MudBlazor/MudBlazor/projects/13#card-84986599, but it does seem to be aligned, right? |
Oh, sorry. Was sure it was the other way around. 🙈 |
@henon What do you think? |
Another consideration I just thought of is that some negative property names reflect the underlying html attributes. We could change Disabled to Enabled but the attribute on the elements is still called disabled. I not sure it's wise to introduce a disparity in those situations. |
Yes we are striving to get more consistency, positive property names and .Net-Compatible naming conventions like Another thing that really annoys me are event names like OnClick or OnKeyDown. In my opinion the event should be |
I'm ok with this one, but as you mentioned, the "On-" prefix would be more appropriate for naming the event handler, rather than the event itself. However, I still believe that some kind of prefix or suffix should be used instead of using the bare "Click" name. "Click" looks like a property or attribute, and a name like "ClickEvent" (for example) would help distinguish it from properties. |
I might be in minority here but imho naming events with prepositions and handlers with descriptive verbs that clearly outline their actions, such as |
@BieleckiLtd now is the time to make breaking changes. We have decided to make the next release v7.0.0 The problem is that we have no overview over all the little discrepancies and inconsistencies. If you like you could help cataloging them and we'd then decide on a renaming action. |
I've also noticed that different components behave differently when their two-way bound parameters change. For example, when I use
|
This problem will be gone once all components start to use |
Do most web/Blazor projects prefer |
Let me know if you'd like me to analyse other boolean properties or look at other repositories. |
@henon Web frameworks: Fluent UI is a mixed bag when deviating from the default
MUI like negative property names
AntBlazor prefer affirming names
They all seem to agree it should be |
Feature request type
Other
Component name
No response
Is your feature request related to a problem?
This is because it is difficult to understand them when reading code. Instead of providing negative property names like
Disabled
it is much easier to think in positive forms, especially when there is a need to inverse the statement programmatically. In such cases, we end up with double negation which can be mind-bending. For exampleDisabled="false"
is harder to understand thanIsEnabled="true"
. Negated boolean properties such asNotEnabled
,NotVisible
must also be avoided, but thankfully I have not seen any in MudBlazor.For anyone who would like to read more, I found a couple of interesting articles about this problem:
Describe the solution you'd like
Discourage
Disabled
,Hidden
and similar property names. PromoteIsEnabled
,IsVisible
etc. instead.Have you seen this feature anywhere else?
Most API's follow this practice
Describe alternatives you've considered
No response
Pull Request
Code of Conduct
The text was updated successfully, but these errors were encountered: