Ancestors

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 | More toots from mattcomi@hachyderm.io

Descendants

Written by mattcomi on 2025-01-14 at 04:06

Another developer quirk of mine (this one is particularly quirky).

If I'm conforming to a protocol, and a function is being intentionally left blank, I'll put the opening and closing brackets on the same line, after the declaration.

struct ConsoleLogger: Logger {

func flush() {}

}

This signals that the function has been left blank deliberately, not accidentally.

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

Written by mattcomi on 2025-01-24 at 07:28

Here's another one of my (Swift) developer quirks: I break my guards into separate lines.

I do this:

guard let provider = widgetProvider() else { return nil }

guard let widget = provider?.widget else { return nil }

guard widget.isFancy else { return nil }

Not this:

guard let widget = widgetProvider()?.widget, widget.isFancy else { return nil }

This makes it possible to use breakpoints to instantly determine what's wrong with the widget. If you used the single guard, you'd have to do some digging to work out exactly where it failed.

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

Written by Guy English on 2025-01-09 at 03:42

@mattcomi This is the way. When not dealing with types coming from C land that’s what we do too. Default is sort of considered a code smell.

=> More informations about this toot | More toots from Gte@mastodon.social

Written by Ryan Booker on 2025-01-09 at 03:55

@Gte @mattcomi Ditto. I'm not sure why, but if I do need a default I also prefer case _. I can't really justify it. 😅

=> More informations about this toot | More toots from ryanbooker@mastodon.social

Written by Matt Massicotte on 2025-01-09 at 10:54

@mattcomi I sometimes exploit default as a way to implement a more complex it/else construct, and it has bitten me on occasion.

=> More informations about this toot | More toots from mattiem@mastodon.social

Written by Russell Ivanovic on 2025-01-14 at 04:31

@mattcomi ha. Same. So far all your crazy quirks just seem like the way I program. What if everyone does this?!

=> More informations about this toot | More toots from rustyshelf@mastodon.social

Written by Russell Ivanovic on 2025-01-24 at 23:05

@mattcomi ok. We have ceased to be identical. I guess we really are two different people. Also you are now banned from my code base for this heresy.

=> More informations about this toot | More toots from rustyshelf@mastodon.social

Written by mattcomi on 2025-01-25 at 03:03

@rustyshelf ok cool, I’m just going to add a calendar event for Jan 25, 2025: the day we became sworn enemies. I suggest you do the same.

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

Written by Russell Ivanovic on 2025-01-25 at 03:05

@mattcomi don’t worry. Siri added a reminder next January to alienate and swerve Jeremy. I’m sure I’ll remember what that means.

=> More informations about this toot | More toots from rustyshelf@mastodon.social

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

This content has been proxied by September (3851b).