I often find that ! characters (meaning not in C-based languages) are easy to overlook. So I sometimes create methods that return the inverse result. For example, instead of doing this:if (!dataContext.Permissions.HasAccessToFeature(FeatureX)) { ... }...I create a second method that is the inverse of the other, making the code read as follows:if (dataContext.Permissions.DeniedAccessToFeature(FeatureX)) { ... }I feel this makes the code more readable, but I'm wondering if others agree?
Is it easier to read and maintain code using ! characters, or implying Not in the method name?
c#;coding style
I think the second variant could lead to more confusion. true should imply positive results, and false a negative result. The question in natural language is usually Are you allowed to access the feature?, not Are you not allowed to access the feature?. The response then is also consistent - Yes you are allowed to access the feature vs Yes, you are not allowed to access the feature.What happens in your second case when you want to check for the opposite result, where a user does have access to the feature?if (!dataContext.Permissions.DeniedAccessToFeature(FeatureX))If the ! operator really confuses you that much, why don't you just doif (dataContext.Permissions.HasAccessToFeature(FeatureX) == false)Regarding one part of your question:...I create a second method that is the inverse of the otherOn a meta level, do you really think it is wise to have two different methods which perform the same task? What happens if the logic needs to change, but only one method is updated because your inverse method is only used in a few places?