Posts

Showing posts from November, 2023

Choose your Expression: Structural Matching, IF-ELSE, and Dictionaries

Image
 So, I have a command line utility that collects and presents some time-series data. What it is isn't important, but dates are involved. You can specify start dates and/or end dates with options --after and --until .  If you specify neither, you get everything. This programming idea is not so interesting on its own, and I have multiple expressions that all work just fine. It's not a programming puzzle I am here to present. Instead, I'm curious about which version speaks to you, which teaches you, which repulses you.  More than that, I'm interested in WHY.  Here is an if-the-else version: Here is a similar version using a dictionary: And one that uses structural matching: Some people will naturally prefer if/else for the simple reason of familiarity. They see a lot of if/then/else logic, and so there isn't much to learn or think about. They may call it "simpler' but it is not.  The dictionary version has more parts, but they're very simple parts, and al...