6 ms·
This appears to have been written by someone who thinks the point of "Hello World" is to print the string "Hello World" as efficiently as possible. If that were
by tptacek 7y ago
This appears to have been written by someone who thinks the point of "Hello World" is to print the string "Hello World" as efficiently as possible. If that were the case, Kernighan wouldn't have written the first one with "printf()".
- kick 7y agoHe didn't write the first one with "printf()". https://www.bell-labs.com/usr/dmr/www/btut.pdf https://www.bell-labs.com/usr/dmr/www/btut.pdf
- tptacek 7y agoBecause he didn't have it in B. The K&R C "Hello World" uses printf(), which itself does a whole bunch of crap other than printing out "hello world".
- saagarjha 7y agoMhm, like being recognized as constant by the compiler and turned into a call to puts?
- tptacek 7y agoSomething Kernighan's compiler didn't do.
- overgard 7y agoHow is a 40 year old compiler relevant?
- tptacek 7y agoKernighan had puts(3) available, but chose printf(3), which does a lot more than puts. The point is Kernighan, not the compiler.
- saagarjha 7y agoTheir libc probably put the characters out slowly one-by-one for both of them, so the difference was probably just a branch or two. Not a whole set of extra syscalls.
- overgard 7y agoWhy shouldn't we expect a compiler to emit the most efficient code? Isn't that the point? If they're not emitting the most efficient code on "hello world", that's a thing. It's not groundbreaking, but, I'd like whatever language I choose to be efficient with the small things as well as the large things. I know what you're going to say. "printf does a lot more". Ok. But can I statically analyze: printf("hello world"), and notice that it's not doing anything interesting with zero ambiguity?
- tptacek 7y agoKernighan's compiler didn't do that, and he had puts(3) available, because he, you know, invented it at the same time. Was he just a suboptimal C programmer?
- overgard 7y agoNice dodge, but the question is: should the compiler emit the most efficient code possible, or not? I don't care what Kernighan's compiler did, I care what's possible. It's been 40 years. What do we got?
- tptacek 7y agoI'm sorry, I don't understand what this has to do with the point I made. I was talking about Kernighan, not about the most efficient possible modern implementation.
- overgard 7y agoWell, maybe I missed your point then. Is your critique that the author used "printf"? I was responding to this statement: > This appears to have been written by someone who thinks the point of "Hello World" is to print the string "Hello World" as efficiently as possible. To me... that would straightforwardly seem to be the point of writing a hello world program.
- 7y ago