Live data from Hacker News

I've implemented a new HTTP/1.1 request and response parser by hand

four.livejournal.com

1–10 of 44 posts

Re: I've implemented a new HTTP/1.1 request and response parser by hand

#2
For a couple of reasons this code doesn't look like a very reliable one...

Almost identical cases don't reuse code (not even a define). There are also sections like "`if (usual[ch >> 5] & (1

    if (!parser->FOR##_mark) return 0; \
    assert(parser->FOR##_mark); \
Sure - speed++, but at what cost? Otherwise... cool code - I like the MARK / CALLBACK macros.

Re: I've implemented a new HTTP/1.1 request and response parser by hand

#4
post #2

For a couple of reasons this code doesn't look like a very reliable one... Almost identical cases don't reuse code (not even a define). There are also sections like "`if (usual[ch >> 5] & (1 if (!parser->FOR##_mark) return 0; \ assert(parser->FOR##_mark); \ Sure - speed++, but at what cost? Otherwise... cool code - I like the MARK / CALLBACK macros.

"I can make it arbitrarily fast if I don't actually have to make it work": http://blogs.msdn.com/larryosterman/archive/2009/09/29/i-can...

Re: I've implemented a new HTTP/1.1 request and response parser by hand

#5
I need to dig through my old computer and find my college lab assignments where we built a basic HTTP/1.1 server. For the request parser, we had to create a lex file for a grammar that include actions for all of the verbs, and also be robust to accept non-standard verbs, i.e, return a 400 code.

I doubt that my yacc'd program would be only 124 bytes in size, but it would be interesting to get that old code and compare the results.

Re: I've implemented a new HTTP/1.1 request and response parser by hand

#6
post #4
post #2

For a couple of reasons this code doesn't look like a very reliable one... Almost identical cases don't reuse code (not even a define). There are also sections like "`if (usual[ch >> 5] & (1 if (!parser->FOR##_mark) return 0; \ assert(parser->FOR##_mark); \ Sure - speed++, but at what cost? Otherwise... cool code - I like the MARK / CALLBACK macros.

"I can make it arbitrarily fast if I don't actually have to make it work": http://blogs.msdn.com/larryosterman/archive/2009/09/29/i-can...

I'm disappointed that the student who hardcoded the results was disqualified. You should get points for finding bugs in your professors' specification.

Re: I've implemented a new HTTP/1.1 request and response parser by hand

#7
post #4
post #2

For a couple of reasons this code doesn't look like a very reliable one... Almost identical cases don't reuse code (not even a define). There are also sections like "`if (usual[ch >> 5] & (1 if (!parser->FOR##_mark) return 0; \ assert(parser->FOR##_mark); \ Sure - speed++, but at what cost? Otherwise... cool code - I like the MARK / CALLBACK macros.

"I can make it arbitrarily fast if I don't actually have to make it work": http://blogs.msdn.com/larryosterman/archive/2009/09/29/i-can...

After reading that, I wonder if trie-s (i.e. judy arrays) would beat hash tables in this exercise... (and I also think that hardcoding the results wasn't cheating)

Re: I've implemented a new HTTP/1.1 request and response parser by hand

#8
post #2

For a couple of reasons this code doesn't look like a very reliable one... Almost identical cases don't reuse code (not even a define). There are also sections like "`if (usual[ch >> 5] & (1 if (!parser->FOR##_mark) return 0; \ assert(parser->FOR##_mark); \ Sure - speed++, but at what cost? Otherwise... cool code - I like the MARK / CALLBACK macros.

> Sure - speed++, but at what cost?

it only has to be written once. i think it's an important enough problem to warrant such code - definitely could use a few more macros though

Re: I've implemented a new HTTP/1.1 request and response parser by hand

#10
post #4
post #2

For a couple of reasons this code doesn't look like a very reliable one... Almost identical cases don't reuse code (not even a define). There are also sections like "`if (usual[ch >> 5] & (1 if (!parser->FOR##_mark) return 0; \ assert(parser->FOR##_mark); \ Sure - speed++, but at what cost? Otherwise... cool code - I like the MARK / CALLBACK macros.

"I can make it arbitrarily fast if I don't actually have to make it work": http://blogs.msdn.com/larryosterman/archive/2009/09/29/i-can...

I've seen that line referenced a couple of times here recently. I'm pretty sure it derives from Jerry Weinberg's Psychology of Computer Programming, which contains a story about some programmers defending an incorrect program on the grounds that it would process more cards per minute, to which Weinberg replied, "But your code doesn't work. If mine doesn't have to work I can do a million cards a minute!"

One of my favorite software stories.

Post reply on HN