Hacker News new | ask | show | jobs
by hilariously 15 days ago
I think you and and your parent are in agreement, you CAN do something, but it's not useful, and then you have to either by convention or additional fields deal with the leading zeros and other non-numeric aspects of phone numbers.

I would also teach young programmers (about data) with the shorthand used above, things like "Do you want to add phone numbers? Multiply them? Utilize fractional components? Why are we storing these as numbers?"

1 comments

I'm not sure we are. My parent suggested you could, in the sense of why would you. I'm questioning if it's possible at all. And if so, is that just based on a local solution. Ie all numbers have an implicit 0 at the start.

To me storing as a number to save space is a fine goal itself. The issue is the underlying complexity which a bare int can't capture. Suggesting using an int indicates the proposer hasn't thought about the issue.

This isn't to say the parent was wrong person se. Asking why you are doing something is a good question. But also understanding the issue/complexity is important too.

In the example I would say that saving space is a sufficient reason, so the point is moot. The reason why you wouldn't want to do it is because a phone number is not 'just a number' (I'm sure there's a mathematical term for a number where leading zeros are important etc).

> I'm questioning if it's possible

It’s certainly possible, but you’ll regret it. Deeply.

Recognising terrible ideas is an essential skill for software engineers.

So the UK starts phone numbers with a 0 generally. International numbers 00 (or plus)

You can't represent a leading zero and because there's 2 for an international code you either rely on the 2 not conflicting. So in the UK's case, the international code is 0044 you would have to rely on no other countries using 044 for domestic numbers.

You could get around that by using the sign bit so +44 is literally a positive integer and a non international prefix is negative?

Then there's the non standard phone numbers, eg emergency services. How do they play with all this. Does 0999 or 0911 work? Does that work internationally?

The biggest issue that I can't see around is that Australia's emergency number is 000. How do you encode that as an integer? How do you differentiate from the old US operator number of 0?

The problem is a leading 0 isn't nothing in a phone number. But it is in an integer on a computer.

So then we're left with the definition of possible. Maybe you can encode all the numbers in your particular region. That's possible. But you can't encode any legal phone number globally.

“But why would you need to keep phones from other countries? All your clients will always be under your own area code.”

I used to make comments like that to highlight the absurdity of all this. I have a Leslie Nielsen level of deadpan delivery.

I read it as a Socraticish anti-question - answering it will answer why its a bad idea.
The use of "What could possibly go wrong" as a provocation, to make students explore what actually can go wrong when we provide a terrible idea (or a good one that has a couple terrible aspects hidden inside them)