views:

1426

answers:

23

I'm in the process of going back over some of the more minor TODO's in my code. One of them is in a class that handles partial dates, e.g. Jan 2001. It works fine for dates that will be seen in our system (1990 - 2099) and gracefully fails for other dates.

The TODO that I've left for myself is that I don't handle dates in the century 2100 and beyond. I don't really think it worth the effort fixing this particular problem, but I am cognisant of the Y2k bugs. If we were in 2080 already I think I'd be thinking differently and would fix the bug.

So how long does code last for? How far ahead should we plan for our systems to keep running for?

Update

Ok, thanks for all your input. I think I'm going for the option of leave the TODO in the code and do nothing. The thoughts I found most interesting were:

  • @Adrian - Eternity, I think that's the most correct assumption, your point about VM's is a good one.
  • @jan-hancic - It depends, yes it does.
  • @chris-ballance - I'm guessing I'll be dead by the time this restriction is hit, so they can come defile my grave if they want, but I'll be dead, so I'll just haunt his ass.

The reason I decided to do nothing was simple. It added negligable business value, the other things that needed looking at did add value so I'll do them first and if I get the time I'll fix it, but really it'll be nothing more than an academic exercise.

+1  A: 

It depends on how much business value the code has and how much resources it takes to write it from scratch. The more value and resources the longer it lasts. Ten years and more is typical for commercial "works, don't touch it" code.

sharptooth
+20  A: 

You can't have a general answer here. Depends on what kind of project you are building. If you are writing software for a space probe then you might want to code it so that it will work for the next 100 years and more. But if you are programming a special Xmas offer for your company's web page, a few weeks should be enough ...

Jan Hančič
Good answer, I once heard somewhere that code has an average use life of about 7 years... but I could be wrong.
Zoidberg
@Zoidberg, I also read that good software takes ten years, which means that on average code is bad :)
Andreas Brinck
@Andreas - Which sounds about right.
ldigas
don't forget that your code for the Christmas offer WILL be used next year, because it's already written.
alexanderpas
+31  A: 

Eternity.

Given the trend that old system keep running in virtual machines, we must assume that all useful code will run forever. There are many system that run since the 60ies, eg backend code in financial sector, and there seems to be no indication that these systems will ever get replaced. (And in the meantime, the frontend is being replaced every other year with the latest fad in web technology. So, the closer your code is to the core of your system, the more likely it will run forever.)

Adrian
It's more like those systems get replaced all the time, piece by piece, to accomodate market and legislation changes. You may well end up with not a single line of the original code remaning, yet it's still considered the same system.
Michael Borgwardt
@michael true enough, these system keep evolving (we might even say, only am evolving system will run forever). However, current research indicates that is unlikely that every line will change during the evolution, system typically fall apart in stable and ever-changing parts.
Adrian
This is a very, very old question indeed :) Ship of Theseus - http://en.wikipedia.org/wiki/Ship_of_Theseus
Binary Worrier
Right, I knew there was an old fable or riddle using that concept, but didn't know what it was called.
Michael Borgwardt
Also see references to the Science fiction Author Vernor Vinge and Code archeologists.
Tim Williscroft
+61  A: 

Longer than you expect.

Michael Borgwardt
+1 . Possibly *much* longer :-)
Brian Agnew
+1. I've written code that was meant to be used for 20 *minutes* and ended up being used for more than 3 *years*. The result was not fun to maintain.
Aaronaught
I just got done "mostly" replacing an intranet application. Some of that code was dated from 1996.
chris
...even when you take this answer into account.
Bill the Lizard
+3  A: 

I don´t think the code will last so long. Think about all the inventions and progress made in the last 90 years.

In 2100 we won´t have to write down code. There will be some kind of brain-machine interface.

Doc Snuggles
Then we'll probably be using those brain-machine interfaces to *write code*. Promises to replace "writing code" with X have been around for decades, but never delivered. Examples for X: 5GL, RAD tools, CASE, MDA.
Michael Borgwardt
See what Fred Brooks has to say about essential and accidental complexities. Or, consider this quote: "Make everything as simple as possible, and no simpler." There's a certain level of complexity that programs necessarily have. Or, from an episode of the Batman animated series: "You don't want to be in my mind. It's not a pleasant place."
David Thornley
I've already got a brain-machine interface: it's called my keyboard. Keyboards were not responsible for Y2K, so I don't see how a new brain-machine interface could fix anything other than possibly RSI.
Ken
Who will write/maintain the brain-machine interface then?
RCIX
A: 

Here are my two cents:

When we design a project, we usually declare it to last "at least" 5 years. Usually no more than 10 years before we re-design it and build it all over. (We're talking about mid-large size projects here).

What usually happens is that the new project you build is supposed to replace the old one, either techonology wise (i.e. moving from MF to windows, VB to .net etc.), but this project never ends. So your client ends up working with 2 systems at once and that leftover system is what later is referred to as "legacy".

If you wait long enough, a third project will rise causing the client to work with 3 systems at once and so on...

But to answer your question, I would bet on 5-10 years before redesign, and unless your dates are supposed to be long into the future - no need to worry about the 2100 limitation.

Faruz
+8  A: 

Sometimes, code lasts longer than you think. But, more important is the slippery slope argument. Once you forgive yourself a bit of non-bullet-proofness, you may be tempted to optimize further and skimp on logical correctness, until it finally bites you.

By the way, I recommend to have an issue ID (such as FogBugz case number) in every TODO comment, so that people can actually subscribe to and track this TODO.

Pavel Radzivilovsky
I like the idea of having a bugid for each TODO, but that becomes a problem in enterprises that track defects rigorously as these kind of shops have issues with defects that are in the "open" status for months (years?). Also, in these kind of shops, it's generally frowned on to make changes to code that are not driven by defects reported by customers.
Ed Griebel
Isn't the slippery slope argument normally considered a fallacy just because there *might* actually be a middle ground?
waxwing
It is a logical fallacy, but it becomes a valid argument when it's humans who do the work. We might just not be able to always find the middle ground, and it's better to stay further away from the disaster.
Pavel Radzivilovsky
+1  A: 

I always tried to code like my applications must work "forever". I am very sure I wont be around anymore in 2100 but knowing my software has a build in expiration date doesn't make me feel good. If you know about such things try to avoid them! You will never know but some unknown programmer in the future may be grateful.

Holli
Do you need to handle the fact that we'll need to revise the notion of leap years somewhere before Feb 29, 100000? The rotation of the earth is not that predictable apparently. There are limits, obviously, but what is sane and what isn't?
MSalters
@MSalters: sane is to program to the calendar we are currently using. If we change the way leap years work, then it's not the same calendar any more: that's the difference between the Julian and Gregorian calendars. Likewise, nobody will blame your software for failing to use the Martian Revolutionary Calendar, when that's introduced in AD 3762.
Steve Jessop
+9  A: 

Nobody really knows. Professional programming has been around for 30-40 years, so nobody really knows if code is going to last for 100 years. But if the Y2K bug is an indication, it is that a lot of code is going to stick around for a lot longer than the programmer intended. Keep in mind that even if you take that into account, it could still stick around longer than you expected. No matter how much you prepare, it might still outlive it's intended life expectancy.

My advice is to not plan for code to last 100 years. Instead try to make sure all your code will work for the same length of time, that is, part of it should not fail in 2 years, while the other part should fail in 100 years. Remember, you should always fix the weakest link first, so there is no point making the strongest link stronger.

Marius
+4  A: 

in Dan Bernstein's immortal words: Don't contribute to the Y10K problem!

just somebody
+2  A: 

Well, we recently made a timestamp format where time is stored in a unsigned 64-bit integer as microseconds from 1970. It will last until the year 586912, which should be enough.

Coding for "forever" is unnecessary - of course you could use BigIntegers and such everywhere, but why? Just be prepared for more than 5 or 10 years. Twenty year old production code is not quite unusual nowadays, and I suspect that the average life cycle will get even longer in the near future.

Joonas Pulakka
A: 

IMHO it comes down to craftmanship : the pride we take in our work, coding to a standard we would not be ashamed another real coder to see.

In the case of dates like this, you've stated that it gracefully fails after 2100. This sounds like you can remove the TODO without a bad conscience, because you have built in a response that will allow the cause of failure to be easily diagnosed and fixed in the (however likely or unlikely) circumstance that a failure occurs.

Steve De Caux
A: 

There are examples of code running on older machines which is 40 or 50 years old.

(Interesting bits in this thread: http://developers.slashdot.org/developers/08/05/11/1759213.shtml).

You've got to ask yourself about the nature of the problem you're solving but generally speaking even "quick fixes" will be around for years so you could realistically be looking at a decade or more for code intended to have a decent shelf life.

The other things you need to think about is:

1) What is the "active life" of the application - that is where it's going to be used and processing.

2) What is the "inactive life" of the application - that is it's not going to be used day to day but might be used for retrieving and viewing old records. For instance UK audit law means that records need to be available for 7 years, so that's potentially 7 years from last system use.

3) What is the range of future data it needs to handle? For instance say you're taking down credit card expiry dates - you can have a card which won't expire for a decade. Can you handle that date?

The answers to these questions will generally lead you to the assumption that you should never knowingly write code which has date constraints beyond those the OS/Language you're using dictates.

Jon Hopkins
+1  A: 

Right up until the time that it breaks, or otherwise ceases to be useful, and then for a bit longer after that

I was going to say just long enough to fail miserably.
ElGringoGrande
A: 

3-5 years max. After that you have moved on to another job and left your crappy code behind.

yedd
I've been in my job 10 years. Some of the code I rely on is over 30 years old.
slim
-1 reckless. if Dante lived today, 8th circle would be for programmers who dumped shit on others.
just somebody
A: 

The question isn't "How long does code last?" but rather "How long will things in my code affect an application?"

Even if your code is replaced, it's possible that it will get replaced with code that does the exact same thing. To some extent, this is the direct cause of the Y2K problem. More to the point, it is the direct cause of the Y2038 problem.

R. Bemrose
+9  A: 

Assume that whoever will maintain the code is a psychopath and has your home address.

Chris Ballance
There's a little psychoder in all of us.
Chris S
A: 

Also keep in mind what you mean by last.

For example, the original UNIX operating was developed 30 years ago. But during that 30 years, the product has evolved over time.

Though, it wouldn't surprise me if a little but of original code still exists in it today.

So think of it 2 ways ... 1) do you ever antisipate the code being touched in the future, 2) the product/code will evolve if you have support and involvmment.

GregN
+1  A: 

The essential things are:

  1. How good is your internal date class (get a very robust library version and stick to it!)

  2. It's not just the passage of time, but also the growth in the range of inputs your users want. For example, maybe you have 30 year mortgage inputs now, but next month someone decides to input a 99 year lease with maturity 2110, or a 100 year Disney bond!

If you accept 2 digit year inputs with a date window, think very carefully about how that is applied to start and end dates, and give lots of immediate feedback.

Erik Olson
A: 

My current shop has a large code base that runs financial applications with complex business rules. Some of these rules are encoded in stored procedures, some in triggers, and some in 3gl and 4gl application code. There is running code from the late 90's, and none of it in your "traditional" Legacy languages like COBOL or FORTRAN. As one could imagine, it's a steaming pile of spaghetti code, most created before TDD meant anything, so people are reluctant to touch anything.

Ed Griebel
A: 

I have had occasion to be brought in on contract more than a decade after the fact to consult on porting code to a new platform (OS/2 just isn't that popular these days!). When in doubt, assume that your code will live longer than you will. At the very least, document the heck out of limitations like this; fix them unless that takes tremendously more work than to document them.

Joe Mabel
A: 

In 1995 I started work at a new job, on an 8 year old code base. So it's incept date was 1987 or thereabouts.

The code is probably still in service. Thats what ? 23 years.
There's been some moves of the company, but they probably kept the software ( because it works) If it's still in service now, it will still be in service in a decade or so.

It's not surprising, particularly high tech code, in C (mostly)

In 1999 I started at a new job, the the codebase had antecedents back to 1984. The new version I designed in the 2000's is still in service, with design elements like data file formats from the previous one ( and so on back) and that would be a development program over 26 years.

So the year 2086 problem is starting to loom a little as those 32 bit signed time_t's roll over.

Tim Williscroft
A: 

Remember that one of the major bonuses of modern programming is reuse.

So that means the code you write originally to solve one problem may get re-purposed and used in a completely different scenario years later (maybe even without your knowledge, by a team mate).

As a side note: One of the major pluses of automated unit testing, is testing code that you can't even remember is there in a system! :)

Alex Key