By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: Code Smell 04 – Stop Abusing Strings—Use Real Objects Instead | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > Code Smell 04 – Stop Abusing Strings—Use Real Objects Instead | HackerNoon
Computing

Code Smell 04 – Stop Abusing Strings—Use Real Objects Instead | HackerNoon

News Room
Last updated: 2025/08/28 at 8:37 PM
News Room Published 28 August 2025
Share
Code Smell 04 – Stop Abusing Strings—Use Real Objects Instead | HackerNoon
SHARE

Too much parsing, exploding, regex, strcmp, strpos and string manipulation functions.

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

Problems 😔

  • Complexity
  • Readability
  • Maintainability
  • Lack of abstractions
  • Fragile logic
  • Hidden intent
  • Hard debugging
  • Poor modeling
  • Regex mess

Solutions 😃

  1. Work with objects instead.
  2. Replace strings with data structures dealing with object relations.
  3. Go back to Perl 🙂
  4. identify bijection problems between real objects and the strings.

Examples

  • Serializers
  • Parsers

Context 💬

When you abuse strings, you try to represent structured concepts with plain text.

You parse, explode, and regex your way around instead of modeling the domain.

This creates fragile code that breaks with small input changes.

Sample Code 📖

Wrong 🚫

<?php

$schoolDescription = 'College of Springfield';

preg_match('/[^ ]*$/', $schoolDescription, $results);
$location = $results[0]; // $location = 'Springfield'.

$school = preg_split('/[s,]+/', $schoolDescription, 3)[0]; 
//'College'

Right 👉

<?

class School {
    private $name;
    private $location;

    function description() {
        return $this->name . ' of ' . $this->location->name;
    }
}

Detection 🔍

  • Semi-Automatic

Automated detection is not easy.

If your code uses too many string functions, linters can trigger a warning.

Tags 🏷️

  • Primitive Obsession

Level 🔋

  • Beginner

Why the Bijection Is Important 🗺️

You must mirror the real-world domain in your code.

When you flatten roles, addresses, or money into raw strings, you lose control.

This mismatch leads to errors, duplication, and weak models.

One-to-one mapping between domain and code gives you clarity and robustness.

AI Generation 🤖

AI generators often produce string-abusing code because it looks shorter and easier.

The generated solution can be correct for toy cases but fragile in real systems.

AI Detection 🧲

You can instruct AI tools to replace string checks with domain objects.

With clear prompts, AI can spot and fix string abuse effectively.

Try Them! 🛠

Remember: AI Assistants make lots of mistakes

Suggested Prompt: Convert it to more declarative

| Without Proper Instructions | With Specific Instructions |
|—-|—-|
| ChatGPT | ChatGPT |
| Claude | Claude |
| Perplexity | Perplexity |
| Copilot | Copilot |
| You | You |
| Gemini | Gemini |
| DeepSeek | DeepSeek |
| Meta AI | Meta AI |
| Grok | Grok |
| Qwen | Qwen |

Conclusion 🏁

Don’t abuse strings.

Favor real objects.

Add missing protocol to distinguish them from raw strings.

Relations 👩‍❤️‍💋‍👨

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxv

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxv

https://maximilianocontieri.com/code-smell-295-string-concatenation?embedable=true

More Information 📕

Credits 🙏

Photo by Nathaniel Shuman on Unsplash


This article is part of the CodeSmell Series.

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-i-xqz3evd?embedable=true

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Steven Spielberg And Halle Berry’s Forgotten Sci-Fi Series Is Getting A Second Life On Netflix – BGR Steven Spielberg And Halle Berry’s Forgotten Sci-Fi Series Is Getting A Second Life On Netflix – BGR
Next Article I Love My Oura Ring but These Cheaper Alternatives Track Your Sleep Almost As Well — From Just  in the Labor Day Sales I Love My Oura Ring but These Cheaper Alternatives Track Your Sleep Almost As Well — From Just $39 in the Labor Day Sales
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

‘Flying’ Tesla Roadster To Demo in 2025, Musk Claims
‘Flying’ Tesla Roadster To Demo in 2025, Musk Claims
News
The 8 best Windows laptops of 2025, tested by us
The 8 best Windows laptops of 2025, tested by us
News
the mythical episode that changed the history of television
the mythical episode that changed the history of television
Mobile
The giant Thales radar which allows France to keep an eye on space
The giant Thales radar which allows France to keep an eye on space
Mobile

You Might also Like

ChatGPT as a soccer advisor: Seattle Reign FC coach uses AI to develop new defensive strategy — and it worked
Computing

ChatGPT as a soccer advisor: Seattle Reign FC coach uses AI to develop new defensive strategy — and it worked

2 Min Read
Go: Can It Mitigate Supply Chain Attacks? | HackerNoon
Computing

Go: Can It Mitigate Supply Chain Attacks? | HackerNoon

11 Min Read
The Hidden Ledger of Code: Tracking the Carbon Debt Inside Our Software | HackerNoon
Computing

The Hidden Ledger of Code: Tracking the Carbon Debt Inside Our Software | HackerNoon

13 Min Read
Beyond Brute Force: 4 Secrets to Smaller, Smarter, and Dramatically Cheaper AI | HackerNoon
Computing

Beyond Brute Force: 4 Secrets to Smaller, Smarter, and Dramatically Cheaper AI | HackerNoon

10 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?