Hacker News new | ask | show | jobs
by OskarS 2582 days ago
If you want this package to be a quality package that can be used in production, there are many more steps you need to take. Determining if you have access to "the internet" is not a trivial thing. Off the top of my head, here are some things you should consider doing:

1. Use platform-native APIs. Both Windows and macOS has apis for this [0] [1], and you are not going to know better than them. Use the "test websites" option only as a fallback or on platforms that aren't supported.

2. Remove all burned-in IP addresses and use system DNS. Since the whole point of this is to make a generic "can the system reach the internet" indicator that is never going to be 100% accurate, you can pretty much just say that "if you don't have access to DNS, you don't have access to the internet".

3. Make sure it works with IPv6.

4. Have a long list (at least 20-30, preferably more) of servers that you check, of companies you can be very sure will not go down. Things like "google.com", "apple.com", "microsoft.com", etc (other good endpoints have been suggested in this thread). When you want to check if you have internet, pick a random 5 and check if any of them works. Consider censorship here, Wikipedia is not going to work for you because it's blocked in many countries. Also: try and find sites that are cool with you using them like this, which I imagine will be a challenge. Preferably, you should get explicit permission.

(honestly, I'm unsure about this part. It feels very skeevy to use these kinds of sites in this way, but it's hard to think of an alternative. I guess check what sites other libraries that provides this kind of support uses)

5. Preferably provide some extended error information. Is the problem that we don't have any network adapters, or a cable not plugged in?

Point number 1 would probably be the most important thing, since that's a genuinely annoying and difficult thing to do. That might be worthy of a package/crate that properly abstracts away the native APIs. But if I were to even consider using this for anything, I would want a FAR more robust system than what you cooked up.

In regards to your comment about engineers: what your package does is trivial. It makes two requests and than reports if either worked. If this is what I wanted, it would have taken me ten minutes to write my own version.

If I had tasked an engineer with a task that could be solved this trivially, and their solution was to pull in an external dependency you have no control over, that would be unacceptable. It would fail code-review in a second and we would have a serious chat about what their job is. I realize that JavaScript and NPM has a different culture, but for systems programming for production use, this would simply not be an acceptable solution.

An engineer is not just a person who "put pieces together". An engineer also considers questions like "what is the cost of using this piece? What are the risks with bringing in an external dependency? What is the code quality of this dependency? Is any of these costs bigger than writing the code myself, from scratch?" As an engineer, you have a responsibility to ensure the robustness and stability of the whole system over the long term. It not just your job to slap together a few packages and call it a day when the CI build passes. A package/crate is not just "free code, yay!". Every dependency you add to any project brings with it costs and risks.

I hate to be this harsh. I understand your eagerness to contribute to open source, and I commend you for that instinct. But when you "Show HN", we're going to give you our honest opinions.

[0]: https://docs.microsoft.com/en-gb/windows/desktop/api/netlist...

[1]: https://stackoverflow.com/questions/15184490/check-for-activ...