Toot

Written by mattcomi on 2025-01-09 at 03:29

One of my developer quirks, (i.e. a sign that you're looking at my code) is that I avoid 'default' in switch statements. If a new enum case is added, I want my code to break. For example, I don't do this:

switch format {

case .date: // Handle date

case .dateTime: // Handle dateTime

default: break

}

If a new kind of date format is added, (e.g. dateTimeLocal), this will continue to compile. This is bad. I want the compiler to direct my attention to this switch so that I know I need to support the new case. My code would look like this:

switch format {

case .date: // Handle date

case .dateTime: // Handle dateTime

case .text, .richText, .number:

break

}

If a new type is added (date or otherwise), I’ll be forced to revisit this switch.

=> More informations about this toot | View the thread | More toots from mattcomi@hachyderm.io

Mentions

Tags

Proxy Information
Original URL
gemini://mastogem.picasoft.net/toot/113796276741224590
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
225.410388 milliseconds
Gemini-to-HTML Time
0.569707 milliseconds

This content has been proxied by September (ba2dc).