Strings vs Slices: a Love Triangle with Characters 💔🧵
dev.to·3h·
Discuss: DEV
🎯Escape Analysis
Preview
Report Post

Every developer eventually stands at this crossroads:

“Do I treat this string like a civilized adult… or do I slice it into little byte goblins and hope for the best?”

If you’ve ever printed "🙂" and got four mysterious numbers instead, congratulations—you’ve met UTF-8 in a dark alley.

Let’s break it down. No gaslighting. No sugar. Just facts, vibes, and a little brain rot.


Option 1: Treating strings as bytes

(a.k.a. “It works on ASCII, ship it”)

In languages like Go, a string is basically:

“Here’s a read-only bag of bytes. Do not ask questions.”

Pros

🚀 Fast. Like ‘blink and you missed it’ fast

🧠 Simple mental model

📦 No extra memory allocations

Perfect for:

  • Protocols
  • File formats
  • ASCII-only data
  • When performance is king and Unicode is a rumor …

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help