Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Confusing method names because of capitalization

ID: java/confusing-method-nameKind: problemSecurity severity: Severity: recommendationPrecision: highTags:   - quality   - maintainability   - readability   - namingQuery suites:   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

It is bad practice to have methods in a class with names that differ only in their capitalization. This can be confusing and lead to mistakes.

Recommendation

Name the methods to make the distinction between them clear.

Example

The following example shows a class that contains two methods:toUri andtoURI. One or both of them should be renamed.

publicclassInternetResource{privateStringprotocol;privateStringhost;privateStringpath;// ...publicStringtoUri(){returnprotocol+"://"+host+"/"+path;}// ...publicStringtoURI(){returntoUri();}}

References

  • R. C. Martin,Clean Code: A Handbook of Agile Software Craftsmanship, 17.N4. Prentice Hall, 2008.


[8]ページ先頭

©2009-2025 Movatter.jp