Wednesday, July 18, 2018 [Tweets] [Favorites]

strftime’s Alpha-sorted man Page vs. Well-meaning People

rachelbythebay (Hacker News):

What happened? Someone read the strftime man page, and %G alpha-sorts before %Y, so they found it first. Then they didn’t “get” the whole warning there, and it looked good enough, so they went with it. The rest pretty much follows from that.

The immediate fix is to change the %G to a %Y, naturally.

A better fix is to get people away from using format strings altogether. Do you really want all of your programmers learning this lesson? Or, do you want to have one person get it right, provide a handful of functions to render the approved formats for either “now” or a supplied time, and then ban all other attempts to use the strings directly, and then go on with life?

[…]

So, the next time your favorite site or app (or built-in tool, hello Apple!) breaks in the last week of one year or the first week of the next, and then “mysteriously fixes itself” three or four days later, it might just be this.

rachelbythebay (Hacker News):

The question is: whatever will we do to stop the next new person from making the same honest mistake?

Put it another way: the me of 2018 knows this. The me of 1998 probably did not. Both of those people wrote code that’s still around running in systems all over the place. What’s the difference? 20 more years of experience. I did not show up knowing all of this stuff. Quite the contrary.

[…]

What if none of the values of X include the funky days where %Y and %G differ? The tests will all pass. You might even have 100% code and branch coverage… but the bug will still be there.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment