3 ms·
Both options looked bad from the start, and only got worse. Why do I need a class with getters and setters, in-place mutation, a pointless toString and a (muta
by filoeleven 4y ago
Both options looked bad from the start, and only got worse. Why do I need a class with getters and setters, in-place mutation, a pointless toString and a (mutable!) static count variable, instead of:
{
title: “a grumpy programmer’s rant about objects”,
body: “Wait, hear me out y’all…”,
published: true
}
Both the Python and ruby examples have no post-ID, so mutating in-place is an extra-bad idea. It should not be the default.
Why does the static count variable exist? These things are all stored in some list (memory, db, whatever, perhaps multiple places) and we can count any subset of those that fits our purpose. What happens when I’m asked to add draft posts? Should I only update the count only if published == true? It depends on whether I’m looking at “number of blog posts” as a user or “my drafts” as an author.
Why does the toString exist? Nobody uses those in real app code for end-users, they are a convenience for developers. Use a better REPL/debugging environment that can handle pretty-printing data. If you need more customization, use a function.
Please, just use plain data wherever possible. Please use languages that support and encourage using plain data. Please push mutation to the edges of the system, and please carefully control the in-place updates. The computers in our pockets are more powerful than anything that existed on earth before 199x, yet the industry is still acting like we’re running them on 8086 microprocessors with 640k RAM.
Let’s grow up and think more deeply about building robust systems which can evolve with changing needs.
EDIT: Changed published to true, because this is basically that.