On Having a Data Object

Internet splits: one-size-fits-all data box or a box for every job

TLDR: A viral post argues against one catch‑all data model and urges context‑specific ones to avoid giant, messy code. Commenters split between predictability for newcomers, selective models to prevent mistakes, and pragmatic “use the tool until it hurts” vibes—this matters because it shapes how teams build safer, faster software.

A spicy blog post just tossed a grenade into a sacred coder habit: the “one data object” to rule every task. The author says stop cramming everything into a single mega-class—like a 2,000-line Hat file—and start using different shapes for different moments. Translation for the non-nerds: your app’s “hat info” shouldn’t be the same hat in the warehouse, the hat in the checkout, and the hat in the design studio. Cue the comment-section brawl. One camp, led by reillyse, argues the real win is predictability: newcomers expect a simple, single data thing, and onboarding stays smooth. “Least surprise,” they chant. The other side fires back that it’s context or chaos, with hexbin010 pointing out you don’t want your “make a user” flow to even see a password when you’re just showing a profile—hello, preventable mistakes. Then the philosophy squad arrives: codemonkey-zeta jokes the author is an inch from a “Clojure epiphany,” preaching that data are just facts, and facts shift by situation. Meanwhile, pragmatists like oftenwrong wave the “ship it” flag—ORMS (tools that auto-handle databases) are fine until they’re not; swap them out when they hurt. Memes? Plenty. LOTR riffs (“One Hat to rule them all”), “hats off” puns, and cries of “DTO stands for Don’t Trust Objects” kept the popcorn flowing.

Key Points

  • The article critiques the common practice of using a single data object to manage a domain’s persistence interactions.
  • It argues different contexts require distinct models, aligning with DDD’s bounded context concept.
  • Using one object across contexts leads to incorrect “optional” fields, extra validation, and testing challenges.
  • Treating different access patterns as the same pushes messy flag-laden methods, breaking encapsulation and increasing bugs.
  • Central data classes tend to grow very large, causing coupling, misleading types, and hard-to-test code, which the author has seen fail in practice.

Hottest takes

"follow the principle of \"least surprise\"" — reillyse
"I'd never want a single UserDTO used for creating and displaying a user" — hexbin010
"Author is on the verge of having a Clojure epiphany." — codemonkey-zeta
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.