Avoid Jumbled Acronyms for Clarity
TL;DR: Treat acronyms like normal words to improve human readability.
Problems
- Reduced readability
- Breaking naming style
- Words confusion
- Harder to pronounce
Solutions
- Treat acronyms as Capitalized words
- Use camelCase or snake_case
Context
Acronyms in uppercase (like JSON, XML, REST) in camel case break the natural reading flow.
You may think sendJSONRequest is a clear name, but it makes your code harder to read, especially when you string multiple acronyms together.
Treating acronyms like normal words in camelCase (sendJsonRequest) keeps your code more readable and easier to understand.
Sample Code
Wrong
class NetworkConnector {
func validateXMLFile() { /*...*/ }
func sendJSONRequest() { /*...*/ }
func parseURLResponse() { /*...*/ }
func setRESTAPIURL() { /*...*/ }
func retrieveHTTPStatusCode() { /*...*/ }
func updateDBConnection() { /*...*/ }
func configureSSLCertificate() { /*...*/ }
func setHTMLTemplate() { /*...*/ }
func generateUUID() { /*...*/ }
func connectViaFTP() { /*...*/ }
}
Right
class NetworkConnector {
func validateXmlFile() { /*...*/ }
func sendJsonRequest() { /*...*/ }
func parseUrlResponse() { /*...*/ }
func setRestApiUrl() { /*...*/ }
func retrieveHttpStatusCode() { /*...*/ }
func updateDbConnection() { /*...*/ }
func configureSslCertificate() { /*...*/ }
func setHtmlTemplate() { /*...*/ }
func generateUuid() { /*...*/ }
func connectViaFtp() { /*...*/ }
}
Detection
[X] Semi-Automatic
It would help if you had a smart thesaurus.
To detect this smell, look for methods or variable names with uppercase acronyms that disrupt readability.
Code reviewers or linters can also flag camelCase inconsistencies.
Tags
- Code Standards
Level
[X] Beginner
AI Generation
Modern AI code generators may produce inconsistent acronym casing.
Always review and adjust their output to match your conventions.
AI Detection
With prompts, AI can fix these naming issues and suggest improvements based on camelCase style.
Try Them!
Remember: AI Assistants make lots of mistakes
Without Proper Instructions | With Specific Instructions |
---|---|
ChatGPT | ChatGPT |
Claude | Claude |
Perplexity | Perplexity |
Copilot | Copilot |
Gemini | Gemini |
Conclusion
Naming conventions are key to readable code.
Treat acronyms like normal words, and avoid uppercase blocks to keep your code easy to understand.
Relations
Code Smell 48 - Code Without Standards
Maxi Contieri ・ Dec 10 '20
More Info
Disclaimer
Code Smells are my opinion.
Credits
Photo by Csabi Elter on Unsplash
Thank you @daniel Moka for this tip.
Simple can be harder than complex
Steve Jobs
Software Engineering Great Quotes
Maxi Contieri ・ Dec 28 '20
This article is part of the CodeSmell Series.
Top comments (3)
I'm torn on short names such as "ID".
Should I write
.getRecordId()
or.getRecordID()
?Don't you mean ChatGpt? :P
Nice catch! IT is a template and I've been making the mistake myself!