Quotes of the week
Posted Mar 15, 2012 9:41 UTC (Thu)
by rvfh (guest, #31018)
[Link] (1 responses)
Posted Mar 16, 2012 11:46 UTC (Fri)
by ebirdie (guest, #512)
[Link]
My add: In the end one better to make it clear, on top of user-space and everything sits (or shits) the user. Crap have to flow both ways, if it is plays between.
My addition has a reference to quote of Andrew Morton above Torvald's.
Posted Mar 17, 2012 20:08 UTC (Sat)
by giraffedata (guest, #1954)
[Link] (5 responses)
I know a lot of programmers have trained themselves to think like computers (or maybe it's that people who already think like computers are the ones who can tolerate programming), so that the two views are one and the same.
Posted Mar 22, 2012 10:44 UTC (Thu)
by elanthis (guest, #6227)
[Link] (4 responses)
That of course includes much/most kernel code.
Note that there's still a big difference between unmaintainable efficient code and readable sane efficient code. In cases where it's hard to make code both, use comments and heavily describe the black magic in the code.
Posted Mar 23, 2012 2:14 UTC (Fri)
by giraffedata (guest, #1954)
[Link] (3 responses)
But if you looked at my C code and typical C code where both do the same thing, even if there is no appreciable difference in execution cost, you would see an obvious pervasive difference. The author of the typical code was thinking of von Neumann CPUs when he wrote it; you can almost see the program counter turning in your head as the lines of C go by. It treats variables like registers, you can clearly see branching going on, and you won't see "const" anywhere, since that doesn't affect generated code.
Posted Mar 30, 2012 21:03 UTC (Fri)
by cbf123 (guest, #74020)
[Link] (2 responses)
That said, I'm firmly in the "comment why you are doing something, not what you are doing" unless the mechanics of what is being done is non-obvious enough to need explanation. It needs to be readable by the next person to look at it (which may be yourself in ten years by which time you've forgotten all the details).
Posted Mar 31, 2012 2:31 UTC (Sat)
by giraffedata (guest, #1954)
[Link]
"assert" is similar. The original theory behind a coded assertion is that it could help the compiler generate better code, but I'm pretty sure that has never been realized. I use lots of asserts and the purpose is neither to generate better code nor to make the program crash when the assertion fails. Like const, it's to help the reader read the code.
Posted Apr 2, 2012 13:08 UTC (Mon)
by jwakely (subscriber, #60262)
[Link]
If the variable definition and everything you do to the variable is visible to the compiler (either because it's all in one file or you have global optimisation) then the compiler knows if it's modified or not, adding const doesn't help optimisation. If the definition is in one translation unit but most operations on it are in different translation units which get a pointer-to-const (or reference-to-const) those other TUs can't know whether the variable was really declared const, adding const to the definition doesn't help optimisation.
http://www.gotw.ca/gotw/081.htm
Posted Mar 24, 2012 19:54 UTC (Sat)
by oldtomas (guest, #72579)
[Link]
Quotes of the week
Quotes of the week
I go further than Andrew. I say the human reader is the primary consumer of a program. In fact, I say a proper program written in high level language is not instructions to a computer but rather a description of the solution to a computational problem. A compiler's job is to understand that solution and generate instructions to cause a computer to compute it.
Telling the computer vs telling the reader
Telling the computer vs telling the reader
It's more of a direction than a destination, so other factors such as runtime efficiency do weigh in.
Telling the computer vs telling the reader
const absolutely affects generated code
I know the theory that the compiler can do better optimization with const, but I've never been able to isolate a particular case where it does. In any case, I know the vast majority of my consts won't affect generated code, and the main reason is that they are on variables private to the compilation unit, so the compiler can see without my help whether the variable gets set or not.
const absolutely affects generated code
const absolutely affects generated code
It's as the old masters say:
Quotes of the week
Let us change our traditional attitude to the construction of programs. Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.
Donald Knuth, Literate Programming
