If you miss a comma, you are concatenating
TL;DR: Watch out for fancy language assumptions
Problems
Possible defects
The least surprise principle violation
Hidden Assumptions
Solutions
Be declarative
Use good linters
Prefer declarative languages
Context
Many programming languages favor laziness over readability and clean code.
You should use them with caution and trust your tests.
Sample Code
Wrong
tools = [
"Amazon Codewhisperer",
"Bard" # Notice the missing comma
"ChatGPT",
"Dalle-E" # Also here
"Eliza"
]
print(len(tools))
# This will output 3
print(tools)
# ['Amazon Codewhisperer', 'BardChatGPT', 'Dalle-EEliza']
# Missing Commas act as hidden string concatenators
Right
tools = [
"Amazon Codewhisperer",
"Bard",
"ChatGPT",
"Dalle-E",
"Eliza"
]
# We added all the missing commas
print(len(tools))
# 5
print(tools)
# ['Amazon Codewhisperer', 'Bard', 'ChatGPT', 'Dalle-E', 'Eliza']
Detection
[X] Semi-Automatic
Many linters warn about this problem.
Also, ChatGPT and Bard can detect the problem.
Tags
- Readability
Conclusion
Many modern programming languages come with a significant amount of accidental complexity.
They are often optimized for writing code quickly, even though they may be prone to defects.
Unfortunately, when working with these languages, it is essential to exercise extreme caution.
Relations
Code Smell 84 - Max < Min (Javascript)
Maxi Contieri ・ Jul 20 '21
Code Smell 69 - Big Bang (JavaScript Ridiculous Castings)
Maxi Contieri ・ May 4 '21
Disclaimer
Code Smells are my opinion.
Credits
Photo by Edge2Edge Media on Unsplash
A programming language is low level when its programs require attention to the irrelevant.
Alan J. Perlis
Software Engineering Great Quotes
Maxi Contieri ・ Dec 28 '20
This article is part of the CodeSmell Series.
How to Find the Stinky parts of your Code
Maxi Contieri ・ May 21 '21
My new book about clean code is available for pre-order.
You will find several recipes like this one with a higher level of detail
Top comments (0)