# What is the oldest line of code still used within Windows?

**URL:** <https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561>\
**Category:** Factual Questions\
**Created:** [July 26, 2022, 2:12am UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561 "2022-07-26T02:12:18Z")\
**Posts on this page:** 14\
**Page:** 3

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [July 29, 2022, 6:07pm UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/41 "2022-07-29T18:07:00Z")

</div>

> [@TriPolar](#):
>
> You still don’t need to sort if you create the index in the right order to start with.

And how do you even find that right order, without sorting?

Let’s say that I have a database consisting of “apple”, “butterfly”, “camel”, “dunkleosteus”, “eschatology”. And then, somewhere along the line, for some unanticipated reason, someone decides that it’s useful to sort those words by their third letter. How do you create the indices for the third-letter sort?

---

<div class="post-metadata">

**Author:** ![TriPolar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tripolar/32/3008_2.png) [@TriPolar](https://boards.straightdope.com/u/TriPolar)\
**Post date:** [July 29, 2022, 6:46pm UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/42 "2022-07-29T18:46:55Z")

</div>

You scan the database one item at a time, look at the 3rd letter of each item, and create an _ID_:_data_ pair entry in an index table using that 3rd letter as _ID_ and the item itself as _data_. In most applications where the database item would be larger and more complex _data_ would be an object ID of the item instead of a copy of it, or might be an object ID anyway for any number of reasons. When the entry is added to the table it is entered in the correct order to start with because the table is a tree of physically non-contiguous nodes which can be navigated to find the location of a data item based on a random ID string whether or not it already exists in the table. The table is performing like memory that can store and return data from locations with random length addresses.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [July 29, 2022, 8:19pm UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/43 "2022-07-29T20:19:01Z")

</div>

OK, so I assign “apple” the ID of “p”, “butterfly” the ID of “t”, “camel” the ID of “m”, “dunkleosteus” the ID of “n”, and “eschatology” the ID of “c”. How does that put them in the right order?

> [@TriPolar](#):
>
> When the entry is added to the table it is entered in the correct order to start with because the table is a tree of physically non-contiguous nodes which can be navigated to find the location of a data item based on a random ID string whether or not it already exists in the table.

If I’m understanding this correctly, you’re using an insertion sort, but pretending that it’s order n, because you’re taking some of the overhead of insertion sort and offloading it into the data structure so you have to do that overhead every time you access the data, instead of just during storage.

---

<div class="post-metadata">

**Author:** ![Dr.Strangelove](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dr.strangelove/32/6613_2.png) [@Dr.Strangelove](https://boards.straightdope.com/u/Dr.Strangelove)\
**Post date:** [July 29, 2022, 8:24pm UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/44 "2022-07-29T20:24:28Z")

</div>

> [@Chronos](#):
>
> If I’m understanding this correctly, you’re using an insertion sort, but pretending that it’s order n

A couple of things:

- A sort via B-tree could certainly be thought of as a fast insertion sort. Since a correctly implemented B-tree has insert/delete times of O(log N), a complete sort will be O(N log N).
- log N is pretty close to constant for large N. So in a big data sense, it’s not entirely wrong to approximate the sort as O(N).

---

<div class="post-metadata">

**Author:** ![TriPolar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tripolar/32/3008_2.png) [@TriPolar](https://boards.straightdope.com/u/TriPolar)\
**Post date:** [July 29, 2022, 8:48pm UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/45 "2022-07-29T20:48:53Z")

</div>

> [@Chronos](#):
>
> OK, so I assign “apple” the ID of “p”, “butterfly” the ID of “t”, “camel” the ID of “m”, “dunkleosteus” the ID of “n”, and “eschatology” the ID of “c”. How does that put them in the right order?

Those entries are stored so they are optimally accessible according to that 3rd letter ID. It’s alphabetical order for simplicity in this case. The IDs are actually bit strings that happen to be small in this example. They’re stored logically in binary numeric order, or higher level constructs such as decimal number order if desired.

The functions of an initial sort are duplicated in keeping the logical order in the B-tree because you are creating a new index. For the B-tree, future insertions and changes to that index continue to insert items in logical order. Otherwise you have to perform some kind of sort or merge operation to add items. This is often done with a temporary table accumulating new data, then periodically sorted and merged with the main table. That requires a two level search for access whenever the table is not up to date. The initial creation of a table may be considered similar in both cases, but after that B-trees don’t have to repeat that whole process.

Access times are superior, databases run non-stop with no need for any table maintenance, data size often is less than raw data size through compression of indexed data, they are far more scalable than other database storage schemes. The ability to manipulate random length data is a natural outgrowth of the technology allowing objects to upgrade their capabilities over time without the need to create new physical structures.

---

<div class="post-metadata">

**Author:** ![md-2000](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@md-2000](https://boards.straightdope.com/u/md-2000)\
**Post date:** [July 30, 2022, 4:03pm UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/46 "2022-07-30T16:03:38Z")

</div>

> [@Sage\_Rat](#):
>
> When it’s worth it, that’s what people do. When it’s not, they don’t.
> 
> [The first rule of optimization is: Don’t do it.](https://news.ycombinator.com/item?id=9196301)
> 
> If everything works fine without the added overhead of indexes, and on-the-fly sorting then hey, everything’s working fine. If it’s not working fine, then people go in and use trees, heaps, etc.

> [@Chronos](#):
>
> And then, somewhere along the line, for some unanticipated reason, someone decides that it’s useful to sort those words by their third letter.

Exactly right. My thought is this - every piece that needs to work flawlessly - sorted tables, dozens of index files - is another way to go wrong. Many of the early PC support issues were files that did not save correctly or somehow became corrupt, power failures caused corrupt files, device malfunctions, etc. The simplest technique was the most reliable. So for example, file headers were simply written to fill the next available entry in the directory structure. File contents filled the next available space on the disk. (There was/is even a simple task you could run to optimize file contents positioning)

Early PC programs evolved with the arrogant but logical assumption they were the only task running on the processor. If it took a second to resort the folder contents - just sort them on the fly by whatever is needed. If I want to filter the contents of the hard drive for th\*.jpg, then it gets done on the fly. It’s not competing with the guy reformatting a book for printing in the next office, or the other fellow doing a report generation from a database, or 30 users in the CompSci class compiling their next assignment. The computer is dedicated to _me._ In microseconds, it has plenty of time to do what it wants.

(Task Manager, for example, can be re-sorting running programs every second for the most active process. That’s easier done from the raw data than updating and writing an index file and then reading that every second. It essentially does the same thing - only, the index is re-created “on the fly” for the GUI in memory, and forgotten when you close the program. What’s the difference?)

I would also suggest that maybe there are elements of the clock program that might be very old. Does windows still calculate from 1/1/1980?

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [July 30, 2022, 10:04pm UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/47 "2022-07-30T22:04:50Z")

</div>

> [@md-2000](#):
>
> I would also suggest that maybe there are elements of the clock program that might be very old. Does windows still calculate from 1/1/1980?

Isn’t it the number of 100 ns intervals elapsed since 12:00 AM January 1, 1601?

---

<div class="post-metadata">

**Author:** ![ftg](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ftg/32/2801_2.png) [@ftg](https://boards.straightdope.com/u/ftg)\
**Post date:** [July 31, 2022, 12:01am UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/48 "2022-07-31T00:01:18Z")

</div>

IIRC, the old BIOS thing was from 1/1/1980 but each field of date (two digits for year, of course) and time was stored separately, and in BCD! This had nothing to do with MS-Windows internal mechanism.

Google is being particularly helpful in leading me to sites that tell me all about setting the OS time and date and not the internal representation regardless of quotes and such.

---

<div class="post-metadata">

**Author:** ![Francis\_Vaughan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/francis_vaughan/32/3093_2.png) [@Francis\_Vaughan](https://boards.straightdope.com/u/Francis_Vaughan)\
**Post date:** [July 31, 2022, 1:00am UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/49 "2022-07-31T01:00:20Z")

</div>

> [@DPRK](#):
>
> Isn’t it the number of 100 ns intervals elapsed since 12:00 AM January 1, 1601?

The start is generally termed the _epoch_.

Useful list:

> **[Epoch (computing)](https://en.wikipedia.org/wiki/Epoch_(computing))**
>
> In computing, an epoch is a fixed date and time used as a reference from which a computer measures system time. Most computer systems determine time as a number representing the seconds removed from a particular arbitrary date and time. For instance, Unix and POSIX measure time as the number of seconds that have passed since Thursday 1 January 1970 00:00:00 UT, a point in time known as the Unix epoch. Windows NT systems, up to and including Windows 11 and Windows Server 2022, measure time as th...

---

<div class="post-metadata">

**Author:** ![Northern\_Piper](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/northern_piper/32/5304_2.png) [@Northern\_Piper](https://boards.straightdope.com/u/Northern_Piper)\
**Post date:** [July 31, 2022, 1:28am UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/50 "2022-07-31T01:28:55Z")

</div>

I find this thread fascinating.

To the extent I can understand it.

Thanks, everyone.

---

<div class="post-metadata">

**Author:** ![md-2000](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@md-2000](https://boards.straightdope.com/u/md-2000)\
**Post date:** [July 31, 2022, 5:57am UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/51 "2022-07-31T05:57:54Z")

</div>

> [@DPRK](#):
>
> Isn’t it the number of 100 ns intervals elapsed since 12:00 AM January 1, 1601?

First I’ve heard of this. Any logical reason? 1600, like 2000, was a leap year while 1700, 1800 and 1900 were _not_ leap years, this complicating the math. More likely, we use the Windows calculation, but will have a Y2K-like problem in Y21C.

I was thinking of a novel I think by Vernor Vinge, where they mention the oddity centuries in the future that the calendars in the computer age counts not from the birth of electronic computers, but 1/1/1980. (Thanks to Microsoft MS-DOS).

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [July 31, 2022, 6:38am UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/52 "2022-07-31T06:38:04Z")

</div>

I can only guess why 1601 (perhaps the real, official reason is documented somewhere?), but it is not any kind of Y2K or Y2.1K problem: the value is a (possibly signed) 64-bit integer, so you are good for a few tens of thousands of years.  
ETA clicking onthe link inside @Francis_Vaughan 's link yields

> [@](#):
>
> Public Service Announcement: This weekend marks the start of Daylight Saving Time in most parts of the United States.
> 
> The `FILETIME` structure records time in the form of 100-nanosecond intervals since January 1, 1601. Why was that date chosen?
> 
> The Gregorian calendar operates on a 400-year cycle, and 1601 is the first year of the cycle that was active at the time Windows NT was being designed. In other words, it was chosen to make the math come out nicely.
> 
> I actually have the email from Dave Cutler confirming this.

but I have no idea what “math come[s] out nicely”, that’s a strange thing to say. Maybe they saved a single addition operation somewhere? Note that the code presumably has to deal with different calendars and time zones and leap seconds and what not anyway.

---

<div class="post-metadata">

**Author:** ![Francis\_Vaughan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/francis_vaughan/32/3093_2.png) [@Francis\_Vaughan](https://boards.straightdope.com/u/Francis_Vaughan)\
**Post date:** [July 31, 2022, 8:23am UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/53 "2022-07-31T08:23:43Z")

</div>

> [@DPRK](#):
>
> but I have no idea what “math come[s] out nicely”,

No, it is idiotic. They were probably re-purposing existing code and didn’t want the additional work of making work correctly.

I have worked with a system that uses 100ns ticks since the real Georgian epoch in October 1582. The less than amusing problem with this is, that whilst it fits inside a 64 bit value easily, it won’t fit inside a Javascript _number_. So neither will the NT clock. No wonder MS hate Javascript.

---

<div class="post-metadata">

**Author:** ![Moonrise](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/moonrise/32/14764_2.png) [@Moonrise](https://boards.straightdope.com/u/Moonrise)\
**Post date:** [July 31, 2022, 11:40am UTC](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561/54 "2022-07-31T11:40:47Z")

</div>

Same here.

I used to be really into computers in the mid-80s. As a matter of fact, I was one of only a couple of kids in the class to have one, a present from my parents on my twelfth birthday. I used to do some extremely rudimentary but fun programming. Then, I lost interest and moved on to other hobbies.

Nowadays, I really don’t care much for computers apart from day-to-day use, but for some reason, I find stories of the early days when it all started fascinating.

[Previous page](https://boards.straightdope.com/t/what-is-the-oldest-line-of-code-still-used-within-windows/968561.md?page=2)
