# Code Smell 218 - Magic Concatenation

> TL;DR: Watch out for fancy language assumptions

# Problems

* Possible defects
    
* The [least surprise principle](https://en.wikipedia.org/wiki/Principle_of_least_astonishment) violation
    
* Hidden Assumptions
    

# Solutions

1. Be declarative
    
2. Use good linters
    
3. 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

```python
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

```python
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](https://chat.openai.com/) and [Bard](https://bard.google.com/) 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

%[https://maximilianocontieri.com/code-smell-84-max-less-min-javascript] 

%[https://maximilianocontieri.com/code-smell-69-big-bang-javascript-ridiculous-castings] 

%[https://maximilianocontieri.com/code-smell-06-too-clever-programmer] 

# Disclaimer

Code Smells are my [opinion](https://maximilianocontieri.com/i-wrote-more-than-90-articles-on-2021-here-is-what-i-learned).

# Credits

Photo by [Edge2Edge Media](https://unsplash.com/@edge2edgemedia) on [Unsplash](https://unsplash.com/photos/t1OalCBUYRc)

---

> A programming language is low level when its programs require attention to the irrelevant.

*Alan J. Perlis*

%[https://maximilianocontieri.com/software-engineering-great-quotes] 

---

This article is part of the CodeSmell Series.

%[https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code] 

---

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

[![Book](https://cdn.hashnode.com/res/hashnode/image/upload/v1689538399958/4ee6e57c-faee-47a1-8ee5-64f5dcf36111.jpeg)](https://amzn.to/44s1XdO)
