-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rationale for API Choices? #78
Comments
This will be fun; I think @njsmith’s API is better. Specifically, even though it adds another interface hook, it turns the implementation into a “single step” parser: only one thing happens at any given time. This is really, really useful. Specifically it ensures that users cannot make the mistake of responding to an event that is no longer valid due to an event later in the iterator. h11’s API could very easily be wrapped in an iterator, so in general the new approach is better. (My new HTTP/2 implementation is a single step parser) |
Yeah, the thing about This wasn't any brilliant insight on my part. Originally events = conn.receive_data(...)
for event in events:
if conn.our_state is ...:
... ...and this was looking at events and Oh, here's the PR: #4 Now... why is it called |
Thanks @Lukasa and @njsmith: The very last bit in the last answer is what I had most in mind: "why is it called
Well, that satisfies my curiosity personally for now. We can close this if you'd like, or keep it open if you want to use it to keep track of any relevant additions to official documentation or whatever else. |
@njsmith: I have a API design question I want to bounce off you, and it seems relevant-enough for here: What do you think about a "bring your own IO"-library requiring a Near as I can tell, there is one downside that is universal, and one that is specifically relevant to the way The universal downside is that it puts somewhat tedious boilerplate code in the happy path of things working as expected. The downside that applies specifically to the The distinction is relevant because for example I think with The hypothetical advantage is that if the connection object refused to let you send more things while data-to-send acknowledgment was pending, it might force some users into doing error-handling logic that they'd otherwise skip. But the cost is lower code "signal-to-noise" because of more boilerplate with explicit acknowledgments, more tedious interactive use (when/if that's relevant), and between that and other factors, reduction-of-programmer-joy (which I know is important because that is literally how Python wins my preference: by bringing enjoyment by having nice abstractions for many things that in other languages would require boilerplate and annoyance and tedious repetitive typing). And honestly the person that was going to skip the tedium of error-checking is probably going to react to being forced into tedium with greater lack of desire to write tedious code, and thus many minds would be more incentivized to just "lie" and acknowledge data as successfully sent as soon as they grab it. I was briefly thinking the tedium could be circumvented with some sort of context manager approach where So at this point I've talked myself into the idea that a Anyway, I think at least some of the above might be worthwhile/educational to have written up somewhere in connection to this project? Because it took me a little bit of playing with the would-be usage before I realized that a But anyway, I'm personally curious if you had thought about doing a |
Is there documentation anywhere for the rationale for the design of the
h11
API, specifically how it deviates from other similar projects?I've noticed for example that
h11.Connection
chooses to expose events using a simplenext_event
method, while two functionally similar abstractions, namelyh2.connection.H2Connection
andmsgpack.Unpacker
, work like iterators, which allows for getting events with eitherfor event in ...
loops or the builtinnext
.Given other evidence that @njsmith does really careful API design with an eye for human friendliness and making correct code easier to write, I suspect that there is some good intuition, experience, or thinking behind this choice, and I would appreciate the documentation going more in-depth on it, as well as any other similarly considered choices.
The text was updated successfully, but these errors were encountered: