What shouldn't most programmers write themselves?

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 8923 Views - Last Post: 16 April 2014 - 04:25 PM

#16 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7806
  • View blog
  • Posts: 13,200
  • Joined: 19-March 11

Re: What shouldn't most programmers write themselves?

Posted 19 March 2014 - 07:31 PM

Date and time is horrible, when you really need to get it right. Just dealing with time zones correctly on an international site is enough to drive you to drink and distraction.

Recently I noticed that Coursera's forums sub this functionality off to the client machine - which led to an interesting bug, since my spare laptop had lost track of time somehow - possibly just losing the time zone, I didn't really get down into it that much. In any case, the coursera forums tag posts by user and time since posting. ("three minutes ago", "six hours ago", "one week ago", that sort of thing). But since my machine was bollixed on the time, I hit the "post" button and saw "posted by Jon Kiparsky, in eight hours".

It made me laugh.

Anyway, yeah: doing date and time correctly will put grey hairs on your head, especially if you have a cranky PM screaming at you to get it right. Libraries FTW. But again, if you have the time and inclination to see what all the fuss is about, you should absolutely try to solve this problem yourself. It's the only way to learn.
Was This Post Helpful? 0
  • +
  • -

#17 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,161
  • Joined: 05-May 12

Re: What shouldn't most programmers write themselves?

Posted 20 March 2014 - 02:46 AM

Now that you mentioned date/times, something related: recurrence patterns for scheduling. Most of the iCal stuff in RFC 5445 (formerly RFC 2445) is pretty simple, but parsing and computing the recurrence patterns for recurring events in a nightmare and a half.
Was This Post Helpful? 0
  • +
  • -

#18 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,161
  • Joined: 05-May 12

Re: What shouldn't most programmers write themselves?

Posted 21 March 2014 - 07:46 PM

And sometimes, you may just be forced to write your own logging because log4net is not the right solution for you. This was the case for my project last year. See my question here. And the response was essentially, log4net assumes that you are in control of the primary executable. If you are writing a ASP.NET web part, a user control, or an Office Addin, and you follow the best practice of putting common code in a separate common code assembly, then log4net is not for you.
Was This Post Helpful? 0
  • +
  • -

#19 Ricky65  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 115
  • Joined: 03-June 10

Re: What shouldn't most programmers write themselves?

Posted 16 April 2014 - 03:52 PM

Binary search. Only 10% of programmers can get it right apparently. Link
Was This Post Helpful? 0
  • +
  • -

#20 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: What shouldn't most programmers write themselves?

Posted 16 April 2014 - 04:25 PM

Link seems to be behind a paywall, but I'm guessing it has to do with integer overflow. Most people write (high + low) / 2 to find the midpoint, but if the high and low values average 1/2 of the maximum value (or greater), the value returned is wrong. low + (high - low) / 2 is the way to go to minimize overflows.

I have some code that makes that error myself, but I don't worry too much about it since you'll need over 1 billion items to cause an issue.

This post has been edited by Momerath: 16 April 2014 - 04:27 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2