New rule: Names of classes, methods, etc. should differ more than only casing

There are multiple languages that are case sensitive. That allows to have classes, methods, properties, and fields to have names that only differ in casing. Although possible, it is a smell of poor design, that I think, deserves a rule.

I’ll give an example in C#, but again, this rule should apply to all languages that are case sensitive.

public class Noncompliant
{
    public int lowercase { get; set; }
    public int lowerCase { get; set; } // Noncompliant
}

As a separate (but very similar) rule, you could argue that names should also differ in more than snake or kebab casing.

3 Likes

I’d second this. I’d also like to add that I think this would also be very useful in the case of visible inherited properties/fields.

2 Likes

… with an exception for either @deprecated methods (Java) or something equivalent in other languages.

I imagine cases, where the casing of the name needs to change lateron, and you need the old version still lying around for compatibility.

Maybe even another exception: if all-but-one of the (non-deprecated) namesakes-modulo-casing merely call that one representative of that group, then that shouldn’t be flagged.

public class Compliant
{
    public int lowercase(String s) { return lowerCase(s); }
    public int lowerCase(String s) { /* lower the case */ }
    @deprecated public int Lowercase(String s) { /* lower the case some other way */ }
}
1 Like

@avl A lot of Sonar rules ignore @deprecated ('[Obsolete] in .NET) code. I fully agree that this should be the case here too.