A bad workman blames his tools
jgc.org
jgc.org
Simply put, a competent programmer reading ESR's posts quickly and correctly comes to the conclusion that he's just not a very good programmer. It feels a bit gratuitous to keep driving that home publicly.
The statement This is, simply put, appalling advice. regarding the advice to try lowering the optimization level to see if the heisenberg goes away. The headline here uses the word "blame" but the referenced article has a headline of When you see a heisenbug in C, suspect your compiler’s optimizer.
Having written a couple of compilers and used many, I agree with the advice to "suspect" the optimization level. Try the lower level, but keep in mind that it could either be a lucky rearrangement of your particular code or a bug in the optimizer.
The -O3 level is widely held to be risky. To me, this means that there is risk of bad code generated, not risk of the resulting program being too fast.
I think the realistic estimate of the probability of errors in gcc is either 1.0 or approaches 1.0, and with -O3 it is not lower.
Yes, lots of people compile lots of programs with gcc and g++, but every shop I have seen has a set of coding standards that suggest or demand avoidance of certain features.
There is a test of a program or specification that gives you a choice between 1) Obviously no deficiencies or 2) No obvious deficiencies. Doesn't seem to me that gcc/g++ (or any other competing compiler) fits either of these criteria.
I've been a blamer of tools as well, but I've convinced myself that it's ultimately wasted effort to do so. Better to simply come to terms with the fact that there do exist bad tools, that they ought to be avoided when reasonable, and that they should be used with care when necessary.
So really "fixed" in this note I guess translates as "moved away from".
Corollary 2: Tools that don't help you catch your mistakes are, in fact, bad tools, and shouldn't be used.
I think it could probably be re-worded as "use the safest tool you can to get the job done."
"A worker uses his tools. A journeyman knows his tools. A craftsman makes his own tools."
"It is rare to find a bug in the OS or the compiler, or even a third-party product or library. The bug is most likely in the application."
http://www.pragprog.com/the-pragmatic-programmer/extracts/ti...
- Do they use source control ?
- Do they use unit tests ?
- What kind of language + environment do they use ?
- Do they have strong opinions about deficiencies of other tools, that they specifically refuse to use? (this shows experience perhaps).Blaming the compiler is an easy cop out and this proves that it rarely actually is the case. This guy is experienced and clever, but he still fell for the its a compiler bug trap. I'm glad he found the real bug and, hopefully, learned his lesson.
I'll reiterate what I said in a comment to the other article - I think that there should be a universal law of programming in languages like C that says that you must, at a minimum, urn compiler warnings to maximum and make sure it compiles without any warning; run your program through tools such as valgrind and ensure it passes without error. And if debugging information of optimizations make bugs appear/disappear then you need to double check everything - its probably a memory alignment issue.
Of course, I've never disassembled MacOSX code, so maybe I'm forgetting something important. If anyone can correct me, I'd be very grateful!
.text
.globl _a
_a:
pushl %ebp
movl %esp, %ebp
pushl %esi
subl $100, %esp
call L_getpid$stub
movl %eax, %ecx
movl $1808407283, -92(%ebp)
movl -92(%ebp), %eax
imull %ecx
sarl $3, %edx
movl %ecx, %eax
sarl $31, %eax
movl %edx, %esi
subl %eax, %esi
movl %esi, -76(%ebp)
movl -76(%ebp), %eax
sall $3, %eax
addl -76(%ebp), %eax
addl %eax, %eax
addl -76(%ebp), %eax
movl %ecx, %edx
subl %eax, %edx
movl %edx, -76(%ebp)
cmpl $0, -76(%ebp)
sete %al
movzbl %al, %eax
movl %eax, 8(%ebp)
addl $100, %esp
popl %esi
leave
ret
.globl _main
_main:
pushl %ebp
movl %esp, %ebp
subl $72, %esp
movl $0, -72(%ebp)
call _a
movl -72(%ebp), %eax
leave
retSigh. I'd love to actually have the time to dig out my Intel opcode books and figure it out, that would be fun, but I have to get myself back into Javascript headspace for work tomorrow morning. I wonder how many layers there are between my Javascript code and processor opcodes...
I think it boils down to -- be humble about whatever context you're operating in -- so as to understand it and use it fully. But that doesn't mean one should stop questioning.
The fact that gcc doesn't warn about a lack of return values (without the appropriate -W flags) is pretty silly. Maybe if you're programming assembly as much as you are C, you don't have to worry about that. But most people who use gcc don't exactly know assembly (though they should!). The tool itself is fairly well-documented, but it's not perfect. Could be improved.
Actually, I don't know. Maybe it is good the way gcc and gdb require the programmer to step up and be more active about the whole process (and maybe learn assembly and how the machine is actually working). So I don't know the right approach. But there is a risk in just 'accepting' tools as they are. Hmm.
I think it's more like -- channel your problem with a tool into a better understanding of what's going on.
A good workman doesn't use bad tools.
A good workman may curse his tools but he nevertheless still gets things done.
A good workman knows his tools well enough to know what they can and cannot do, and does not ask them to do what they cannot.
A good workman is humble and takes the effort to identify a problem before blaming a cause (whether it be the tools, himself, anomalous barometric pressure, or what-have-you).
Very true.
Heisenbugs do not exist, computers are deterministic.
Things that do exist:
Pieces of code that I do not understand. Pieces of code that I have not read. Pieces of code that interact in ways which I do not expect.
Perhaps in your universe.
In mine, I've seen video card temperature, random radio noise on an ungrounded component, and power line noise all totally screw with programs. Diagnosed to the point we could stimulate the errors through environmental changes. Dozens of more errors we think we have the solution to as being caused intermittent effects but can't repro reliably
Computers in theory are deterministic. In practice, they're machines in the world.
the comparisons of "you can't cut a cake with a fork" et al. just doesn't apply here.
php is a 100 pound chain on the productivity of the entire industry. Companies that have embraced php also happen to be examples of companies that achieved way below their potential (yahoo and facebook).
It's funny that as we slay the beasts of perl and j2ee, we bring up another terrifying goul. It's probably why real engineers snicker when we call ourselves software 'engineers'.