5 Edge Cases No Programmer Likes Handling
Tags: jokes, webdev
Published: 2022-10-04 06:32:39

---
title: 5 Edge Cases No Programmer Likes Handling
published: true
description: Some common problems you run into that just kinda mess with your flow, ya know?
tags: jokes, discuss, webdev
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gu5wstkutvmocs1ellbv.jpg
---
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.

```python
message = f"You have {len(items)} item{'s' if len(items) > 1 or len(items) == 0 else ''}"
```

## #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:

```jsx
{
	items.map(stuff =>
		<SuperCoolItem key=stuff.key data=stuff style={{marginBottom: 5}} />
	)
}
```

![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.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4nwl5k7y5w5eufbvzk3g.png)

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 ☕

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

## #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'
```

## #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 <a href="https://unsplash.com/@elisa_ventur?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Elisa Ventur</a> on <a href="https://unsplash.com/s/photos/despair?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>