3 ms·
These should have been strings, end of story. You can sort a string. Amazing to see storing a non-number as as number being defended. Truly CS101.
by pigbearpig 5y ago
These should have been strings, end of story. You can sort a string. Amazing to see storing a non-number as as number being defended. Truly CS101.
- petee 5y agoI'm curious which languages you learned in CS101 (actual question, not snark) Every non-number, as you put it, is just a number to a computer. Comparing binary is faster than sorting strings, and it makes zero sense to waste memory simply so a human could potentially read it.
- jraph 5y agoBut versions are for human beings. Otherwise, a timestamp, a date, a commit hash or an increment would do.
- petee 5y agoThat's not true, they can be for either humans, computers, or both. Software still has to understand and do something with that version number, even if it came from a human. And if it has to store, sort, or process that number a lot, it will still be faster to store and compare binary than a string. For comparison, I think some here would be shocked to learn their IPv4 address is stored as an unsigned 32-bit integer. Its not a number, and definitely not faster to use as a string.
- DSMan195276 5y agoYou can certainly sort a string, but I think there are valid reasons to avoid it if possible. What they shouldn't be doing is trying to shove it into a single 32-bit integer - if they parsed it into separate integers for each of the individual parts (like a simple date representation would do) then the issue would go away. Whether it's worth that extra work to avoid the string comparison is debatable, but if they go on to mask out parts of the version number and look at them individually (Ex. Only the year, or only the revision number) than it would probably be worth it to just do all the parsing upfront and avoid any messing with strings after that.
- srj 5y agoI guess it depends on the language but using a string for this doesn't seem like a great choice except for user display / logging. Given this is a version number you'd want to support comparison operators, and a struct with those operators defined (and a string format method) would make more sense imo.
- mr_toad 5y agoDepends on the language and function. Some sorting algorithms happily rank ‘9’ > ‘10’.