You'd think that is so completely wrong that no competent programmer would ever do it...
Except the java.net.URL.equals and java.net.URL.hashcode methods do almost the same thing: they issue DNS requests (!)
"Two hosts are considered equivalent if both host names can be resolved into the same IP addresses; else if either host name can't be resolved, the host names must be equal without regard to case; or both host names equal to null."
There is a bug raised[1], but it can't be fixed for backwards compatibility reasons.
I'll never forget this now, after debugging a very horrible and severe and very intermittent performance issue in some code over 20 years ago. A (slow) DNS resolver occasionally caused 1000x performance degradation on remote sites. That was horrible to work out.
Ew. Yikes. Wow, that's a special kind of special. The mind truly boggles. It had a score of 4 when I first checked it, but it looks like it got slashdotted by this thread/link and now it's -1 and probably still falling.
The question was how to build a URL, not how to send off a request to it. The answer sends off a request and then inspects the response to see what URL was used. If you wanted to send off the request, inspecting the URL on the result is probably not useful. If you didn't want to send off the request, doing it this was is wasteful or even harmful.
Yes, but unless the answer was edited before the link to HN was posted, the user specifically said you should only do it if you _really_ intend to make a request, not just generate a url. It is conceivable you'd want to log the request or something and hence reference the url after the request call. Yeah, it is a bad answer to the question as stated, but it has a logic to it considering what might be the real motivation behind the question.
EDIT: Apparently the answer was edited by another user just recently making the clarification.
Your parent poster makes the mistake that is rife among Python programmers, which is to assume that in a delightfully simple[0] language like Python, it's "obvious" what a given piece of code does even without explanation. Among people who don't delight in the poor taste of Python's design and have limited exposure to its standard library, of course, it's not always obvious what a given piece of code is doing despite the belief to the contrary, so there are plenty of people who aren't going to pick up on the fact that requests.get doesn't just construct a GET request for the caller, but instead constructs such a request and then goes out and performs it, too.
Shame about the hostile reaction from others towards your question. Keep asking questions (especially things that are presented without comment), and don't be afraid that doing so will make you look stupid or that you should feel like you should be punished for it.
> Shame about the hostile reaction from others towards your question.
I agree that your parent is a good question that should have been well received, but, as far as I can tell, it was. Where do you see a hostile reaction? In fact the only hostility I see in this thread is what you directed at Python, which, in this context, seems unmotivated; it is surely true that one can write code in any language whose full import isn't immediately apparent. At the moment, the only other response to your parent is from hvdijk, saying (https://news.ycombinator.com/item?id=27534803):
> The question was how to build a URL, not how to send off a request to it. The answer sends off a request and then inspects the response to see what URL was used. If you wanted to send off the request, inspecting the URL on the result is probably not useful. If you didn't want to send off the request, doing it this was is wasteful or even harmful.
This seems like a response that takes the question seriously and addresses it clearly, just as it should.
At the time I wrote the comment it was clearly not well-received, and the oblique opening remark from the person you're quoting is not the kind of response that addresses the question as it should.
That comment is, just like the downvotes the question received, precisely the sort of thing that discourages asking honest questions rather than welcoming them. Note that by the way it is written it, too, assumes that it is both obvious and understood that Python's request.get will "send off a request"—instead of merely building a request and returning it to you. Rather than just straightforwardly answering the question (by explaining what this part of the Python' standard library is actually doing—which is the relevant missing piece here, and which no one should be expected to know) the quoted comment ("The question was how to build a URL, not how to send off a request to it") pins the misunderstanding on the questioner by tacitly implying the questioner isn't paying attention to something else entirely different.
The comment, when considered in full and in context, actually has the effect of subtly discouraging/admonishing the questioner (and likeminded people with the same question) for failing to recognize something that is, to the sophomoric Python crowd, obvious and worthy of ridicule—which is what maest's thread was all about, by the way (and almost certainly why it got moderated).
https://stackoverflow.com/a/40429822/864112
It boggles the mind that anyone could ever suggest this as a solution.