Live data from Hacker News

Show HN: Servasm – Literate web server in x86 assembler

zarkzork.com

21–30 of 40 posts

Re: Show HN: Servasm – Literate web server in x86 assembler

#21

Annotations aside, this is actually more readable than a lot of C code I've seen.

Thats funny because C is a one-to-one mapping over assembly. And frankly its not using any esoteric instructions such as "PUNPCKHQDQ" or "VFNMADD231PS"

It is absolutely _NOT_ a one-to-one mapping over assembly. You have no idea how many issues have arisen in ##c because assembly programmers seem to think this is true.

Ask there for examples if you need elaboration, there are people much smarter than myself who will gladly show you the error in your ways.

Re: Show HN: Servasm – Literate web server in x86 assembler

#22

Would love to see benchmark on this versus nginx for fun!

Other than needing to fork for every request, this should be really fast because it uses the efficient sendfile() mechanism in the kernel to handle returning the file and most importantly only implements a bare minimum of support for the protocol. nginx is almost certainly going to be slower because it has to worry about different types of requests, different protocols, IPv4 vs. V6 sockets, CGI, etc...

It's easy to make something fast when you only implement a very small number of features.

Re: Show HN: Servasm – Literate web server in x86 assembler

#23

Would love to see benchmark on this versus nginx for fun!

Other than needing to fork for every request, this should be really fast because it uses the efficient sendfile() mechanism in the kernel to handle returning the file and most importantly only implements a bare minimum of support for the protocol. nginx is almost certainly going to be slower because it has to worry about different types of requests, different protocols, IPv4 vs. V6 sockets, CGI, etc... It's easy to m…

nginx is highly configurable at compile time. You can strip out a considerable amount of functionality (modules, in nginx lingo) for performance.

Re: Show HN: Servasm – Literate web server in x86 assembler

#24
Very nice.

However, I wonder who started this trend of bundling "better commented code" with "literate programming" though?

I appreciate the layout and hyperlinks etc - but this really is just a well-structured assembly program laid out in a way that it won't assemble until after it's been through a pre-processor (I'm talking about the program as presented with html/css etc). It's pretty far from "literate programming".

I suppose one could argue that if you manage to simplify the structure of your program to the point that it reads like prose, one has a "literate program". But it's a strange use of the term. The core idea is to have the code be incidental to the commentary, so that, among other things, one would update the commentary whenever one change the program.

Laying out the comments in a funny way doesn't quite do that. I first saw this with the "literate" re-write of coffee script, but perhaps it's older?

Perhaps the difference between "old" literate programming, and this style ("prose programming"?) is similar to the difference between unit testing and TDD, or between TDD and BDD?

Re: Show HN: Servasm – Literate web server in x86 assembler

#25
post #24

Very nice. However, I wonder who started this trend of bundling "better commented code" with "literate programming" though? I appreciate the layout and hyperlinks etc - but this really is just a well-structured assembly program laid out in a way that it won't assemble until after it's been through a pre-processor (I'm talking about the program as presented with html/css etc). It's pretty far from "literate programmin…

One functional feature that is missing is that of having blocks in different order. Jeremy Ashkenas argues that because of functions, we do not need that reordering.

I disagree with that. I do think a large part of what makes literate programming powerful is that one can easily sculpt the order of the presentation. It elevates the code and comment to telling a story for humans.

I think the code is not incidental, but is part of the aspect of the story, much like in a fictional story one has descriptive passages and dialog passages. If one updates the story, both may change or perhaps just one of them.

My take on literate programming, using markdown: * minimal client at https://www.npmjs.com/package/litpro * core library and docs at https://github.com/jostylr/literate-programming-lib

Re: Show HN: Servasm – Literate web server in x86 assembler

#26
post #25
post #24

Very nice. However, I wonder who started this trend of bundling "better commented code" with "literate programming" though? I appreciate the layout and hyperlinks etc - but this really is just a well-structured assembly program laid out in a way that it won't assemble until after it's been through a pre-processor (I'm talking about the program as presented with html/css etc). It's pretty far from "literate programmin…

One functional feature that is missing is that of having blocks in different order. Jeremy Ashkenas argues that because of functions, we do not need that reordering. I disagree with that. I do think a large part of what makes literate programming powerful is that one can easily sculpt the order of the presentation. It elevates the code and comment to telling a story for humans. I think the code is not incidental, but…

I agree that functions are not usually a good one-to-one fit for abstraction.

If they were, we wouldn't need variables, loops, blocks etc. Now you could argue that we don't, we should just write code in lambda calculus -- but we don't do that.

Especially for languages like assembler and C-like languages, it can be very nice to single out smaller sections of code. And while for eg: C, or I suppose a macro assembler, one might be able to in-line a lot of such blocks -- having to stay at the "block-semantic"-level of the host language can make some things pretty hard to communicate to the human reader in a good way.

Ruby might actually be a good candidate for "simple" literate programming, in the sense that one probably could, and perhaps sometimes should, program ruby much like smalltalk -- no method/function longer than five lines or so, except for the most exceptional circumstances.

Even then, I think one would find patterns that would make sense to abstract out of the "function level", or "language level".

At the other end of the spectrum is too much magic, just as with any meta-programming technique, such as proper macros.

I had a most peculiar experience trying to write some (mostly procedural) java with noweb. It was typical intro programming stuff, basically some very simple data structures/algorithms.

It was a very nice fit for literate programming, but not such a good fit for java -- while the literate program read nicely, and was well structured, the mangled java code was unwieldy -- it turned out I'd ended up generating a java program that did what I wanted.

Now, that's not really a problem, we generate assembly programs that are unwieldy all the time -- but the point is it took some discipline and thought to write a literate program that was also readable in it's tangled form.

Only an issue if people are expected to read/modify it in that state, obviously. And they are, as they'll have to debug it at some point ;-)

> I think the code is not incidental

That was a bit tongue-in-cheek -- I meant more in the sense that comments are incidental to code in most programming languages.

> https://github.com/jostylr/literate-programming-lib

Very nice, thank you for sharing.

Re: Show HN: Servasm – Literate web server in x86 assembler

#27

Would love to see benchmark on this versus nginx for fun!

Other than needing to fork for every request, this should be really fast because it uses the efficient sendfile() mechanism in the kernel to handle returning the file and most importantly only implements a bare minimum of support for the protocol. nginx is almost certainly going to be slower because it has to worry about different types of requests, different protocols, IPv4 vs. V6 sockets, CGI, etc... It's easy to m…

IIRC, Nginx can use sendfile too, it's just not there by default because the transfer happens entirely in kernel space and hence you cannot apply filters like gzip on the response (correct me if I'm wrong).

Re: Show HN: Servasm – Literate web server in x86 assembler

#28

If anyone finds this interesting, and would like to drill down into this type of low level code, I highly recomment "Programming from the Ground Up" by Jonathan Bartlett [1]. It is an excellent introduction to assembler, and programming in general. [1] http://freecomputerbooks.com/Programming-from-the-Ground-Up....

The non-spam link to download is here: http://download.savannah.gnu.org/releases/pgubook/

Re: Show HN: Servasm – Literate web server in x86 assembler

#29
That's really fascinating and interesting and educating.

Now every other http server implementation should need to explain every byte it is larger and every ms it is slower it terms of "why?" and "what for?" and "who gains from this?" ;)

I don't know, for longer already I don't buy this tales about "it needs to be this large because..." ... mostly legacy, abstractions and ease of code maintenance etc. This took us all into the world in which the very smallest app on the phone reacting to a click with a "beep" takes how much memory? And the software development craft accepts unbelievable inefficiencies. Memory, Cpu manufactures for long time added to this fires by essentially mis-nurturing devs by optimizing in the background and by creating an environment of limitless virtual resources. I like how "battery-life" enforces, brings back some old ideas on efficiency and software craftsmanship.

Humanity starts to deal with limits of its planet, its own limits and maybe this kind of thinking will bring back some level of limits into the virtual realms as well? I think we would gain from it.

Re: Show HN: Servasm – Literate web server in x86 assembler

#30
post #26
post #25

Earlier quoted context omitted.

One functional feature that is missing is that of having blocks in different order. Jeremy Ashkenas argues that because of functions, we do not need that reordering. I disagree with that. I do think a large part of what makes literate programming powerful is that one can easily sculpt the order of the presentation. It elevates the code and comment to telling a story for humans. I think the code is not incidental, but…

I agree that functions are not usually a good one-to-one fit for abstraction. If they were, we wouldn't need variables, loops, blocks etc. Now you could argue that we don't, we should just write code in lambda calculus -- but we don't do that. Especially for languages like assembler and C-like languages, it can be very nice to single out smaller sections of code. And while for eg: C, or I suppose a macro assembler, o…

My version of literate-programming may have a bit too much possibility of that magic. I agree it can be dangerous and is something that takes good discipline, like any programming technique. But at least there is something to fall back on in terms of the narrative.

On the flip side of the tangled form, I do appreciate the "flattening" of potential functions. Imagine code that uses a lot of functions, scattered about. It can be hard to follow all that, rather a bit like the GOTO of old (better, to be sure, but still hard to follow). With literate programming one can get the conceptual separation of writing in different blocks, but then they get put back together and the flattened version can be read quite easily, one would hope. So I agree that a locally readable tangled form is very important.

I'd be curious to see your example's code, if you are willing to share it.

Post reply on HN