Enum values: Integer or string?

I’ve been writing software for a few decades and historical momentum has been to define enum values as integers, probably because earlier languages supported integers, not strings.

class Color(Enum):
  UNINITIALIZED: 0
  RED:           1
  GREEN:         2
  BLUE:          3

So it was a surprise when a discussion among engineers went the other direction — encouraging strings as enum values — for newly introduced enums. It seems that industry momentum may have shifted this direction. Here’s a contrived example that I do not recommend:

class Color(Enum):
  UNKNOWN:  ""
  RED:      "rood"     # Note: Dutch
  GREEN:    "verde"    # Note: Spanish
  BLUE:     "bleu"     # Note: French
  LAVINDRE: "lavndir"  # Note: Purposefully misspelled

Benefits of using string enum values include:

  • Clarity when viewing logs. However, it is possible to log integer enum values as strings.
  • Clarity when debugging. However, some debuggers may already add clarity for integer-based enums.
  • Disparate teams across the organization can more readily understand the data without having to refer to documentation.
  • API interoperability and clarity.
  • Ease of adding new items in the middle of the enum, whereas with a sequential integer approach, it is not possible.
  • Default value as empty string. It has always been a pain when an engineer decided to use 0 to indicate anything other than “default”, “uninitialized” or “unknown”, because 0 is often the default value for uninitialized variables and properties. With strings, an empty string is ideal.
  • It’s still possible to represent string-value enums as integers when persisting to a database or interoperating with other systems — although it may require additional work.

Caveats and counter indications:

  • Legacy. Keep what works and don’t break things, especially when disparate systems depend on existing enumerated integers. Translation layers can be a solution.
  • Lack of programming language support, although there are often alternatives including use of constants.
  • When the enum string values are misnamed or poorly named, it can cause confusion and bugs due to misunderstandings.
  • Who gets do decide which human language we use for the string values? Who will be consuming the values? Do they understand the language? I gave my example above with three different language values to emphasize that it’s best to stick with a single language.
  • Misspelled values may need to remain misspelled forever to prevent breaking disparate consumers. Software engineers are human, and they make mistakes. We don’t usually misspell integer values, and when do, the software either won’t compile or won’t run. Translation layers can be a solution.
  • Upper or lower case? Camel case or snake case? Decide on a standard.
  • Performance critical systems and RAM/storage constrained systems may do better with integer values.
  • Some databases support enums — the underlying data is an integer, and the database represents it as a string, including in queries and exports — so it could be possible to get the best of both worlds — performance and clarity for humans.
  • Isolate the churn of a ever-changing names. The integers can stay the same and the enum keys can change to reflect current needs. E.g. marketing names tend to change.

Smart light switch lifetime: Resetting my expectations

I tend to think that an in-wall light switch should last twenty to thirty years. However, I’ve had to reset my expectations with smart switches.

I’ve had a several decora GE Jasco Z-Wave switches in my home for the past 10 years. Four of them lasted seven years before the electronics completely failed. I replaced three of them with new Jasco switches, and one of them with a dumb switch. When another switch stopped reliably responding to button presses after nine years, I replaced it with a traditional “dumb” switch. Another two Z-Wave switches are still going. Of the two, one is used multiple times per day, and the other one is used a few times per week.

Compared to dumb switches, smart switches contain additional complicated electronics — integrated circuits, capacitors, resistors and diodes. They’re more subject to age, “dirty power” and other environmental factors. High quality components can extend the expected lifespan.

There have been a few times when the switches stopped responding, and I’ve had to reset them. They have a small tab to pull, and then push back in. It’s like resetting a GFCI, only more difficult.

Z-Wave has had staying power, and Z-Wave devices communicate locally, so are not subject to the whims of a cloud provider who might decide to end support, or to economic forces that might shutter a business, leaving devices without cloud support. Still, the staying power of the cloud provider, or of a technology, also has an impact on the liftetime of a smart switch.

I expect smart switches to last 7-12 years, and to be less reliable than traditional switches. Is the convenience and automation worth it? Sometimes, yes. Other times, no.

CertSage ACME client and shared hosting

I host my website on asmallorange.com and recently, I noticed that Brave and Chrome would no longer load the website without TLS, and I didn’t have a certificate — it was raw HTTP only. I looked in the cPanel, and the hosting provider wanted too much money to give it a TLS certificate. A web search turned up “CertSage ACME client”, and within 10 minutes, I had it set up and now my site has a proper TLS certificate from Let’s Encrypt. Thank you to everyone who made this possible, and I especially appreciate the vision of Let’s Encrypt.

Engineering mileu and customer experience

We have lived in our house for 17 years, and have replaced three dishwashers — a disappointment because in my mind, even a cheap dishwasher should last 20 years. The first was quite old, inexpensive, and still functional, but was loud and cleaned adequately only when we pre-rinsed all food bits.  After two years, we replaced it with a different brand, a higher-end model with a steel tub — a KitchenAid. It cleaned dishes better — until it didn’t. The plastic roller axles on the lower tray broke, and I replaced them with steel bolts and nuts. The impeller drive motor broke, and I replaced it. The upper tray had plastic that broke, and I repaired and replaced it over four years. My young children sometimes got the twist ties from bread bags in the dishwasher, and I’d eventually find them in the disposal of the dishwasher, and would pull them out, along with gunk.

At some point, the control board fried, I contacted KitchenAid, and they said they’d sell me a new high-end model at a discount price. So I went with that. It wasn’t as much of a discount as I had hoped, and initially, it worked well.

However, over time, it had somewhat similar issues to the previous dishwasher — nylon parts were engineered cheaply, or engineered to fail over time. I replaced things as they broke, and when its ability to clean went downhill, I decided I’d had enough — I would “fire” the previous team of engineers and “fire” the entire process and culture that created the less-than-stellar machine, and “hire” a new team of engineers, with a different process — so we bought a Bosch.

The Bosch is different. No disposal. No heating element. No cheap plastic rollers. It has cleaned well, and has been a joy to use for over two years. It continues to clean well.

I don’t think the engineers from the previous company were inept. They had a different environment and a different set of constraints to work under — an environment that did not serve me, the customer, well. So I found one that had a mileu, culture, insights, and vision that have served our family better.

Printmaster 18.1 on Windows 11

My wife has been using Printmaster for over 25 years, and for the past several years, she’s been using version 18.1. When it stopped working recently, she enlisted my help. It turns out the desktop shortcut not longer functioned — it gave an odd install error. When I created a link to the executable, and pinned that to her toolbar, it worked — it functions again.