CodeQL documentation

Confusing method names because of capitalization

ID: java/confusing-method-name
Kind: problem
Security severity: 
Severity: recommendation
Precision: high
Tags:
   - quality
   - maintainability
   - readability
   - naming
Query 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 and toURI. One or both of them should be renamed.

public class InternetResource
{
	private String protocol;
	private String host;
	private String path;

	// ...

	public String toUri() {
		return protocol + "://" + host + "/" + path;
	}

	// ...

	public String toURI() {
		return toUri();
	}
}

References

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

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy