cover-img

Code Smell 04 - String Abusers

16 July, 2022

7

7

0

Too many parsing, exploding, regex, strcomp, strpos and string manipulation functions.

TL;DR: Use real abstractions and real objects instead of string accidental manipulation.

Problems

Complexity

Readability

Maintainability

Lack of Abstractions

Solutions

1) Work with objects instead.
2) Replace strings with data structures dealing with object relations.
3) Go back to Perl :)
4) Find Bijection problems between real objects and the strings.

Examples

-Serializers
-Parsers

Sample Code

Wrong

Right

Detection

Automated detection is not easy. If code uses too many string functions it can trigger a warning.

Relations

Primitive Obsession

More info

Tags

Mapping

Conclusion

Don't abuse strings. Favor real objects. Find absent protocol to distinguish them from strings.

Credits

This article is part of the CodeSmell Series.

7

7

0

Maxi Contieri

Buenos Aires, Argentina

🎓Learn something new every day.📆 💻CS software engineer 👷coding👨🏽‍🏫teaching ✍🏾writing 🎨Software Design 🏢SOLID 🌉TDD 👴Legacy 💩Code Smells

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2024. Showcase Creators Inc. All rights reserved.