Best search algorithm to find condition within a range

Marko Rauhamaa marko at pacujo.net
Thu Apr 9 14:15:23 EDT 2015


Steven D'Aprano <steve+comp.lang.python at pearwood.info>:

> It's not so much the undefined behaviour part that gets me. That's bad
> enough. But the concept that having the compiler ignore what you write
> in the source code because you've accidentally hit some undefined part
> of the spec *is a feature* rather than a horrible, horrible design
> flaw that blows my mind.

Similar reasoning is applied successfully (albeit dangerously) by
Hotspot, Oracle's Java engine when optimizing multithreading.

If natural code can be successfully optimized with such assumptions,
more power to the optimizers. However, what we have here is the banning
of very natural modulo arithmetic in favor of very questionable
optimization gains. I want the wrapping semantics of integers and
routinely exploit it in my code. I want the integer semantics of enums
and want to gracefully handle range overflows. I don't want the
compiler to intervene and screw my code because it thinks it's broken in
the first place.

> Of course not all C programmers are cowboys. Linux Torvalds has a
> reputation for a zero-tolerance attitude towards kernel bugs, and a
> take-no-prisoners attitude to anyone who might break userspace code
> due to changes in the kernel. But I think that the vast number of
> C/C++ exploitable bugs is proof that most C coders lack either the
> skill or inclination to write correct C code. Even the Linux kernel
> contains bugs. Things were bad enough in the old days of classical C
> compilers, but modern C optimizing compilers may actively counteract
> your code as you have written it. How that isn't considered an
> outright malicious act, I don't know.

I actually guess the point here is to permit optimizations in code
written by complete newbs. The standard allows the optimizer guess the
"real" intentions of the programmer and remove the performance
deficiencies (a newb would use ints and imagine they are ideal
integers). It's a win-win: the newbs are happy for having written
performant code and the optimizers can feel they've accomplished heroic
performance improvements.

The sad result is that the value of C is diminished in the hands of the
experienced programmers.


Marko



More information about the Python-list mailing list