DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for 5 Edge Cases No Programmer Likes Handling
Abdisalan
Abdisalan

Posted on

5 Edge Cases No Programmer Likes Handling

Life is usually simple and our clever little programs can handle most things thrown at it... but sometimes, it's not enough.

That's where edge cases come in. Little, one-off, problems we must handle that disrupt the natural flow of our code.

Here's five edge cases I don't like handling as a Software Engineer.

#5 Plural wording(s)

Showing the user "item" when there's one item. Then also showing them "items" when it's more than one or zero.

We've all been guilty of writing β€œitem(s)” with a parenthesis before, right? 🀨 But sometimes, we've gotta fix the bug.

Look at this monstrosity I had to write the other day. I’m not proud of it, but it works.

message = f"You have {len(items)} item{'s' if len(items) > 1 or len(items) == 0 else ''}"
Enter fullscreen mode Exit fullscreen mode

#4 Styling the last element in a list

You've probably run into this if you're coding React or Vue. Imagine you've rendering a list of items like this:

{
    items.map(stuff =>
        <SuperCoolItem key=stuff.key data=stuff style={{marginBottom: 5}} />
    )
}
Enter fullscreen mode Exit fullscreen mode

Numbers 1 through 9 in a 3 by 3 grid. There's enough padding between rows 1, 2, and 3. However there is too much padding below the 3rd row.

That bottom margin works well...until the last element. So what do we do?

We check if it’s the last element and then set the margin to zero. If you know a better way to do this, perhaps with a cool CSS trick, leave a comment on how! I would look it up, but I’ve moved on to other tasks β˜•

{
    items.map((stuff, index) =>
        <SuperCoolItem key=stuff.key data=stuff style={{
            marginBottom: i == (items.length-1) ? 0 : 5
        }} />
    )
}
Enter fullscreen mode Exit fullscreen mode

#3 Null

Oops! Did you forget to check if the object you were using was actually null? Yea, me too! And in production...

At this point, when I'm not writing TypeScript, I expect these to happen.

JavaScript:
Uncaught TypeError: criticalBusinessObject is undefined

Python:
AttributeError: 'NoneType' object has no attribute 'id'
Enter fullscreen mode Exit fullscreen mode

#2 Time Zones

Oh, your cron jobs were set with a UTC time zone? Really? All our customers are on Pacific time, Abdi! Stop trying to confuse them with a magic timezone no one uses! (sorry to my African and European readers). I’m not even gonna get into it that some time zones are off by 30 minutes πŸ’€.

This is all a lead-in to the real reason I wrote this article. The biggest, most painful issue that comes up twice every year…

#1 Daylight Savings Time

Perhaps the most destructive construct invented by the hubris of man.

Here’s one of the scariest moments in my career. I’m sipping my latte on a beautiful, early spring morning and I hear this:

All our customers got their text messages 1 hour late! I want every engineer in the meeting room now!

β€” startup CTO

In America, only 48 US states observe it. That leaves Hawaii and most of Arizona (Navajo Nation observes Daylight Saving). Also, only about half the countries in the world observe it, and they don't even agree on when it should happen!

Thanks for reading 😊

Those are my top 5! What are yours? Leave a comment below and let's chat about what we don't like 😼

For my fellow Americans, don’t forget that Daylight Savings is November 6 this year and the clocks are falling back. β€œSpring forward, Fall back” β€” good way of remembering.

Photo by Elisa Ventur on Unsplash

Top comments (1)

Collapse
 
jmfayard profile image
Jean-Michel Fayard πŸ‡«πŸ‡·πŸ‡©πŸ‡ͺπŸ‡¬πŸ‡§πŸ‡ͺπŸ‡ΈπŸ‡¨πŸ‡΄

Perhaps the most destructive construct invented by the hubris of man.

So true.
And so hard to fix the bug once it's released in production!

The EU tried to do everything right to make it obsolete, and still the status-quo won, even if no-one would argue for making it the law if it didn't exist.

bloomberg.com/news/articles/2021-0...

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›