THE POWER OF ZERO!!!
Ever notice sorting methods sometimes sort like this 1, 10, 2, 3…and so forth? We surely would expect the sequence to look more like, 1, 2, 3…10. Why does this happen?
The sorting process called lexicographic ordering (sometimes called alphabetical listing of component letters) explains it all. It happens when fields contain both numbers and letters. As soon as letters are introduced, the system reads the list alphabetically similar to a dictionary.
Take for example an Excel sheet with two columns. The first column is comprised of a numeric list, and the second column introduces a letter. When we sort the two columns from smallest to largest (i.e. in ascending order), the results are very different.
Here’s another way to look at the information: think of reading the information in the cell like reading an actual word; we always read from left to right.
In the example below we have two values A200 and A1999. We would assume that A200 would appear before A1999 being the smaller numeric value. However, that’s not the case! We can think of lexicographical ordering as dividing each word into individual letter cells, reading the letters one by one from left to right before sorting. In this example, while both values share “A” as the first character, the second character is different. Now the system compares both characters and determines that “1” is smaller than “2”, hence the value A1999 should be listed first before A200.
A | 1 | 9 | 9 | 9 |
A | 2 | 0 | 0 |
Ok… so why is this important to SnapTracker?
When we create IDs in SnapTracker, such as Buildings and Locations, we often use both numbers and letters. When lexicographic ordering applies, the system is organizing the data out of proper sequence. For example, if we create the following Locations from A-1-10 to A-10-40 and order them in ascending order, we get:
As we can see, the Locations are not ordered in logical sequence!
How do we fix it?
In order to prevent the problem from occurring we need to add a zero to the numbering convention.
For example, instead of using A-1-10, use A-01-10.
A | 0 | 1 |
A | 0 | 2 |
A | 0 | 3 |
A | 0 | 4 |
A | 0 | 5 |
A | 0 | 6 |
A | 0 | 7 |
A | 0 | 8 |
A | 0 | 9 |
A | 1 | 0 |
Effectively O acts as a place holder so that the sequence is displayed properly!
Last but not least, we should always remember to identify the length of your number sequence, based on how many entries such as buildings or locations are being accounted for. If you have more than 99 locations, you need to have more than one zero as a place holder.
01 – 99
001 – 999
0001 – 9999
This simple process of adding zeros to the naming convention will help you make sure your data is organized in proper sequence. It also maintains consistency in the length of information you are creating.