9

At work we have to split a potentially large ID into 2 10-digit long parts that will be passed to an outside system that will later return them with some more data to us.

A colleague had implemented it using regular expression, it passed code review, everything was ok, until he noticed a potential problem. For some cases, because the outside system stores them as int and therefore will remove any leading zeros, there will be no way to reconstruct the number.
So we brainstorm and I propose ether a modified regex, or to just use math like part1 = id % 10^10 and part2 = floor(id % 10^10) and then we can reconstruct it simply by: part2 * 10000000000 + part1

Colleague: - Well, the regex will be faster, there won't be any calculations
Me: - :| I disagree but ok..

We do some more brainstorming and testing and find a case where the proposed new regex fails as well
So I bring up my previous proposal, I explain what exactly it does.

Colleague: - I don't like the math, it has calculations, which won't be needed before we reach the 11th digit

Have I missed some major development in computer hardware? When did they become bad/slow at doing math? :|

Comments
  • 3
    string.Split with some substrings and indexof is a perfect solution !

    It's really clean. While you write it. Good luck figuring the logic about 6 months ago.
  • 4
    Could you not just check the length of part 1 and pad the start with zeros until you get the length you need?
  • 10
    What the fuck did I just read

    I hate everything about this
  • 5
    Either I don't understand the problem well or... WTF ARE YOU DOING?!?! you are parsing gigantic numbers, splitting them using regex, and the passing it off to a outside service, just to do it in reverse?

    Why the gigantic numbers? What are they even for? Why don't you just store it in the format the service requires? Not even as a replacement for the current field (which you should) but even just alongside the current field!!

    It takes only 60GB to store another 64 bit field for a trillion records. I know that sounds like a lot, but if you have a trillion records, you can certainly spare $100 for another TB of storage.

    Can you explain your code more? Am I missing something? Literally none of this should be nessesary.
  • 3
    @deadPix3l IKR. Also why the absolute fuck are we splitting an ID in the first place?
  • 5
    Also since when did regex get faster than divmod? Regex is super slow. (Relatively speaking of course in this post GHz world)
  • 1
    @deadPix3l Yup!! Compared to even number parsing regex is REALLY slow
  • 2
    Your math is wrong. First of all you’re getting 9 digits instead of 10 for the part1 and then for the part2 you’re getting the same result as part1.

    Also wtf 20 digits are longer than 64bit integer who saves it as number...
Add Comment