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
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
Next Article 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

Genode OS 25.08 Introduces New Kernel Scheduler, Updates Linux Drivers
Computing
Credit Bureau TransUnion Hit With Data Breach Affecting 4.4 Million People
News
Teklynx’s Sentinel labelprint automation software transforms production
News
Xiaomi rolls out HyperOS 3 with “super island” interface, similar to Apple’s dynamic island · TechNode
Computing

You Might also Like

Computing

Genode OS 25.08 Introduces New Kernel Scheduler, Updates Linux Drivers

1 Min Read
Computing

Xiaomi rolls out HyperOS 3 with “super island” interface, similar to Apple’s dynamic island · TechNode

1 Min Read
Computing

Google Warns Salesloft OAuth Breach Extends Beyond Salesforce, Impacting All Integrations

3 Min Read
Computing

OBS Studio 32 Beta Introduces A Plugin Manager, Hybrid MOV Support

1 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?