Hacker News new | ask | show | jobs
by bicx 99 days ago
This 1000 times. I’ve tried implementing what OP has mentioned, and quickly learned it isn’t possible. A city can also exist in multiple zip codes. And there can be multiple cities with the same name in the same state. So, to be safe, you have to enter city, state, and zip.
7 comments

I don’t understand either of these arguments. They both appear to reinforce the point made in the article. At worst a zip code contains multiple cities? Voila the city box becomes a dropdown. It’s 2025. JavaScript.
I get the vibe that it's more like there's unexpected complexity and it's difficult to be confident you know how zipcodes work with enough detail to make the feature work. And that is just one example of possible complexity.

Do zipcodes change for example? Can your drop-down quickly go out-of-date? You'd need a way to manually enter a city so people are able to tell the system an address. Do you want to bother making an auto-updating zipcode feature just for a form?

Is it going to confuse people because nobody else has bothered to make this superfancy selection feature thing?

Is this USA only? There are postal codes/zipcode-equivalents in other countries.

It starts to feel it's likely not worth the time and effort to try to be smart about this particular feature. At least not if I'm imagining this us some generic, universal address web form that is supposed to be usable for USA-sized areas.

To me it feels similar to that famous article about what you can and cannot assume about people's names; turns out they can be way more complicated and weird than one might assume.

Although maybe zipcodes don't really go that deep in complexity. But on the spot I would not dare to assume they are.

> Is this USA only? There are postal codes/zipcode-equivalents in other countries.

This is where the real problems start - postcodes exist the world over.

Speaking as someone that has dealt with countries that have postcodes, but no states, so it's just Street Address (if applicable) | City (if applicable) | Country | Postcode

Inputting a "zip code" first would result in every country being in the drop down.

In Australia, addresses too are wild, they should be considered "free form"

https://blog.melissa.com/en-au/global-intelligence/australia...

Gives this as an example address The Smith Family

'Willow Creek' Station

via Winton

QLD 4730

Absolutely its worth the time to get it right.

What kind of app are you building? Maybe you're selling something. You probably want users to get through your check out form as fast as possible before they change their mind or get distracted or frustrated.

Or you're building an app for data entry and people are filling in lots of addresses every day. They would appreciate you saving them time.

Either way, spending a day or two to polish up your form can be worth a lot.

Not saying its trivial to get all the edge cases right, but I'm pretty sure we can do better here.

I just placed a delivery order from home depot and this is exactly how they handled it. I put in my zip, they gave me a drop down of the cities that zip covers (there are like 5 of them, incredibly) and I was on my way.
Indeed. I don't always even do the drop down just make it autofill a still editable text box
Even if a zip code contains multiple cities, each ZIP has one "preferred" locality name and you can default to that. Any of the locality names within a zip code is deliverable for all addresses in that zip code.
As has been pointed out in many other comments implicitly and explicitly, the purpose of a set of address fields in an HTML form is not always to come up with a USPS delivery address.
Does that mean you shouldn't choose sane defaults or...?
Many other comments here have outlined the problems with what TFA appears to consider "sane defaults".

But sure, if you can do it right (e.g. "Put the country first"), then by all means do so!

As long it does become a dropdown, fine.

But in TFA's example it does not (my zip has 3 possible city names; TFA's example shows only 1).

Except that's not what this page does, so it's harder than TFA makes it out to be. I am in a zip code that spans two cities, and it won't let me change the city name at all once I put my zip code in.
> A city can also exist in multiple zip codes. And there can be multiple cities with the same name in the same state.

These are reasons you cannot deduce the Zip from the city, not the opposite. A ZIP+4 actually encodes all other information for a US address.

Nobody knows their +4 code. You cannot ask for information 90%+ of people won't have.
If asking for the zip first was more common then we quickly learn those four extra digits because the auto fill benefits would be immediately obvious
Why?

I have a 4 digit postcode, I have to look it up every time I have to fill in an address form for delivery.

I've had people screw 1 digit up in that postcode and their items (a laptop in one case) went to the completely wrong city.

A code sounds foolproof, until you realise most people don't engage with them for most of their lives - you don't tell the uber driver the zip/post code you are waiting in, and travelling to, nobody does.

edit: just to add - Magic numbers are bad. Software engineers know that a number that's undocumented in code is unmaintainable, a zip code is worse.

> I have a 4 digit postcode, I have to look it up every time I have to fill in an address form for delivery.

> A code sounds foolproof, until you realise most people don't engage with them for most of their lives - you don't tell the uber driver the zip/post code you are waiting in, and travelling to, nobody does.

When the above comments said +4, they meant knowing the second half of the nine digit zip code.

Basically everyone in the US knows the first 5 digits. It's really easy to memorize them. If you can remember your city, you can remember your zip code. And in the US you use it all the time, so it stays memorized.

> edit: just to add - Magic numbers are bad. Software engineers know that a number that's undocumented in code is unmaintainable, a zip code is worse.

That complaint about magic numbers is completely off base. Magic strings are just as bad in software. "Beverly Hills" and 90210 are equal sins on the magic front.

> Basically everyone in the US knows the first 5 digits. It's really easy to memorize them. If you can remember your city, you can remember your zip code. And in the US you use it all the time, so it stays memorized.

What's the 5 digits for Yonkers New York (edited because I originally had NYC)

> That complaint about magic numbers is completely off base. Magic strings are just as bad in software. "Beverly Hills" and 90210 are equal sins on the magic front.

For the same reasons, that's why it would be: Beverly Hills, Los Angelos County, California, USA, 90210

Your zip plus 4 changes. It isn't worth trying to know as it isn't supposed to be constlnt. If you send a lot of mail there is a discount for using it but you have to update everyone's address often (iirt at least 4x per year)
Source? The numbers correspond to the USPS distribution centers and carrier routes. If the numbers are changing that would imply an increase in zip code subdivisions, making each zip code a better address predictor for a given individual.
Of course they do.

Let me uh just grab my utility bill...

10% of the US population is 35 million people. That's a pretty weird version of "nobody".
This is a bad hill to die on for a ux conversation. "10% can feel kind a big number when 100% is huge" is a funny argument, as is trying to be pedantic about "nobody knows" as a shortcut for "most people won't know and you can't rely on any particular user knowing". If 10% is big enough to matter I can't wait to tell you about 90%!
I'm not suggesting that one would design for the 10%, but I also think that writing off 10% - "nobody" - (particularly of a large number of people) is pretty dumb too.
> "10% can feel kind a big number when 100% is huge" is a funny argument

That would be a funny argument if it were the one being made.

A ZIP+4 does not encode all information.

Proof: a post office has its own zip code, for PO Boxes.

The +4 is the last four digits of the post office box.

If the Post Office has more than 10,000 boxes, the +4 will be duplicated.

Yeah, anyone who has had to work with USPS bar codes should know that internally these are called routing codes, and they come in 5, 9 and even 11 digit variants. The 11-digit one narrows down to a specific delivery point, but even that isn’t enough to derive an address (just enough to know whether you’re looking at the right one or not). Zip+4 codes also change frequently because they aren’t based on locations but on delivery routes and sequencing.
> Zip+4 codes also change frequently because they aren’t based on locations but on delivery routes and sequencing.

This was news for me. I know the few zip+4 I memorize never change.

I think the source for the parent is AI slop. See [1].

> Due to an increase in population or to the improve postal operations, the US Postal Service® will occasionally add a new ZIP Code or change ZIP Code boundaries.

The plus four digits encode:

> [67] : Sector or Several Blocks

> [89] : Segment or One Side of a Street

Note that this contradicts the parent.

[1]: https://faq.usps.com/s/article/ZIP-Code-The-Basics

The census bureau (very) periodically publishes zip code data (which is where some places get their geolocation info). If you work with enough addresses you’ll find some zip+4s that are wildly far away from where they used to be. There are paid services that have better accuracy, but I’m not sure how they acquire their data.
Some people don't realize just how much you can "customize" deliverability with the post office, especially if you're big (like a school or large business) - you can have something that looks like your physical address, but is actually really a maildrop/PO Box at the nearby post office.

You can do relatively complex forwarding that would only appear to the end users if they can decode the barcode.

ZIP+4? I think that's literally enough digits to give every house in the US (about 150,000,000 apparently) its own identifier.
Zip isn't uniformly distributed numbers though so you dont have the equivalent of that many digits of decimal numbers. Other comments have more detail but just for the top level example the first number is the zone and goes from 0 on the east coast to 9 on the west.
Only if there's never more than 10,000 addresses in a single zip code, which means that if you enforce that, you can force a zip code to appear by building enough house
I think my point is that if you're going to make people learn a 9-digit identifier for their house you might as well make that identifier unique and then that's the only information they need to fill in. Having non-unique 9-digit identifiers feels wasteful.
That happens, and worse. I've lived in multiple areas that have had their zip code changed. Area codes, too, sometime more than once.
There are far more addresses than there are houses
Wrong. There can also be multiple cities in the same ZIP code. There is not a 1:1 relationship with a 5-digit ZIP as everyone is assuming here.
Make that 1003+ times. At least in my part of the US, even a pretty modest-size city will have multiple zip codes. And zip codes can have zero geographical footprint (meaning street address) - for example, some zip's are just for Post Office Boxes. And a physical address can have an official USPS address & zip of "Middle City", while physically being in (say) Middle Township. And other fun stuff.
>Make that 1003+ times. At least in my part of the US, even a pretty modest-size city will have multiple zip codes.

Is that an issue? Who cares that new york city has 20+ zip codes? Just fill autofill "new york city, new york".

>for example, some zip's are just for Post Office Boxes.

Again, is it bad except for some joker who wants something sent to an invalid address?

I've implemented it, too, and didn't run into any problems. User inputs the zip code, if there's multiple city matches, they select the correct one from the drop-down (or you auto-complete the city name after they type the first 4 letters).

The fact that "A city can also exist in multiple zip codes. And there can be multiple cities with the same name in the same state" is a good point IN FAVOR of asking for the zip code first (NOT to avoid it) because you certainly can't do it the other way round.

And if you just leave it to the user to free-type all that info in, you have to verify it after... Users are going to make typos, and the USPS will kick your butt if you don't correct it (and credit card payments won't go through, either). So it may be less work for web-form creators, but pushing the verification down stream just makes it all worse for the company using it.

The postcode doesn't tell the whole story. But what you can do is use an IP geolocation service which should narrow down your location enough, so that typing in the entire address is no longer necessary.

I.e. using something like https://ipinfo.io/json and then typing in a full postcode and street name + number should work well in most cases.

IP geolocation is increasingly not useful for anything, especially for mobile users. The best it can do is give you the correct country and maybe get you in the right region.
That link nailed me perfectly. I'm on my phone. Connected to wifi, like most people probably are. Chilling in bed or on the toilet.

If you're on cell service.. yeah probably less accurate. Not sure if it makes the form harder to fill out if you have to change some of the fields.

What I've started doing for my personal app though is I've added a "guess" button. It fills in the form using heuristics but it's opt in. Fills out like 10 fields automatically and I've tuned it so it's usually right, and when it isn't correcting a few is still quicker.

I work for IPinfo. The accuracy you see is inferred data actually. Our IP address location should not perfectly pinpoint anyone, unless that IP address is a data center of some sort. The highest accuracy for a non-data center IP address is usually at the ZIP code level. In terms of carrier IP addresses, currently we do one data update per day. If we did more, I guess the accuracy of mobile IP addresses would improve, but on an overall scale, it would be quite miniscule.

Our country-level data (which is free) is 10-15 times larger than the free/paid country-level data out there. We constantly hear that the size of the database is an issue. The size is a consequence of accuracy in the first place. So, it is a balancing act.

> Our IP address location should not perfectly pinpoint anyone, unless that IP address is a data center of some sort.

By perfectly, I meant it got my city and zip correct, but I looked up the lat/lng and its a 5 min drive away. So pretty dang close!

Not sure how you got it that close if its only supposed to point to the nearest data center.

I work for IPinfo. Has our data been inconsistent for you? We actually invest heavily and continuously in data accuracy. I think for hosting IP addresses we are nearing the highest level of accuracy possible, especially with data center addresses. We are investing in novel, cutting-edge research for carrier IP geolocation.

I am curious about your experience with us so far.

What if I order something on the road and want it delivered to my home? Or what if I want to order something over mobile? My mobile IP is often 1500km away from where I live.

Autofill solves all of that with an implementation cost that approaches zero.

There are enough ZIP+4 codes for about a billion addresses. Many addresses I've lived at in the US have had a unique ZIP+4 code.
The digits aren’t random though, some of them have meaning.
> A city can also exist in multiple zip codes.

Sure but a zip code belongs to only one city and one state, right?

No... That was addressed elsewhere. That's the bigger problem