Understanding String Length Calculations for Emojis Across Programming Languages
By
program
A five-star bake. Worth schmearing, sharing, saving.
Summary
This article examines the complex issue of string length calculation for emojis and Unicode characters across different programming languages (JavaScript, Swift, Python). The author argues that JavaScript's approach of returning the number of UTF-16 code units (which gives 7 for "🤦🏼♂️") is actually reasonable, while criticizing Python 3's approach as the worst. The article provides technical explanations about Unicode encoding, grapheme clusters, and why different languages make different design choices for string length calculations.
Key quotes
· 4 pulledFrom time to time, someone shows that in JavaScript the .length of a string containing an emoji results in a number greater than 1 (typically 2) and then proceeds to the conclusion that haha JavaScript is so broken
I will try to convince you that ridiculing JavaScript for this is less insightful than it first appears
Swift's approach to string length isn't unambiguously the best one
Python 3's approach is unambiguously the worst one, though
You might also wanna read
Why Average LLM Use Is Likely Destroying Value in Software Development
The author argues that, contrary to prevailing hype, the average use of Large Language Models (LLMs) is likely destroying value rather than
How AI Accelerated Prototyping: From Idea to Tangible in Record Time
The author reflects on how AI has transformed their prototyping workflow. Previously, the biggest bottleneck was the time needed to scaffold
GitLab 19.0 launches with Secrets Manager, agentic workflows, and self-hosted AI models
GitLab 19.0 has been released, positioning itself as an intelligent orchestration platform for DevSecOps. The release includes expanded secr
bit.ly·1d agoCentralizing Error Handling in Rust with Custom AppError Enums
This article discusses the importance of centralizing error handling in Rust applications using a custom AppError enum combined with map_err
Zig Devlog: Build System Rework Separates Maker and Configurer Processes
This devlog entry from the Zig programming language project announces a major rework of the build system, separating the maker process from
Study finds most developers refuse to code without AI, raising quality concerns
A February 2026 study by AI research lab METR reveals that most developers now refuse to work without AI coding tools. While these tools hel
