CodeSOD: Never retire

We all know that 2038 is going to be a big year. In just 14 years, a bunch of devices will have problems.

Less well known is the Y2030 problem, which is what it is Vencislav fighting to protect us from.

//POPULATE YEAR DROP DOWN LISTS
for (int year = 2000; year <= 2030; year++)

    DYearDropDownList.Items.Add(year.ToString());
    WYearDropDownList.Items.Add(year.ToString());
    MYearDropDownList.Items.Add(year.ToString());


//SELECT THE CURRENT YEAR
string strCurrentYear = DateTime.Now.Year.ToString();
for (int i = 0; i < DYearDropDownList.Items.Count; i++)

    if (DYearDropDownList.Items[i].Text == strCurrentYear)
    
        DYearDropDownList.SelectedIndex = i;
        WYearDropDownList.SelectedIndex = i;
        MYearDropDownList.SelectedIndex = i;
        break;
    

Okay, probably less critical than Y2038, but this code, as you can guess, started life in 2000. Clearly, no one thought it would still be in use this far, but…it is.

It’s also worth noting that the dropdown list object in .NET has SelectedValue property, so that //SELECT THE CURRENT YEAR section is unnecessary and could be replaced with a single line.

In six years, do you think this app will be replaced or will it year the for loop will just change to year <= 2031 and be a manual change for the rest of the app’s lifetime?

I mean, they could change it so it always goes currentYear or currentYear + 1 or whatever, but do we really think that’s a viable option?

[Advertisement]

ProGet has you covered with security and access controls for your NuGet feeds. Find out more.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *