perjantai 4. maaliskuuta 2016

Do-What-I-Mean programming


Occasionally I run onto some minor syntax annoyance with language I happen to be currently using and for a brief moment think that damnit, the compiler should be able to figure out what I mean. This time I was playing with Android and OpenGL ES 2.0, which happens to be just different enough from OpenGL 3.2 I use on desktop to make by stumbling first steps there somewhat annoying.

After few hours of trying to figure out where my simple triangle vanished I tried another version of shaders, and it fails to compile when I tried to assign a vec3 to gl_fragcolor (which is vec4). At that moment I was for a vanishing moment annoyed by compiler - it should be able to know that I don't need alpha at the moment.

Like every time in the (recent) past this thought passed immediately. No, I don't really want compiler to guess what I mean. Quite contrary, I prefer my compiler to be just about strict as possible - dot every i, cross every t kind of strict. Compiler guessing what I want is bad. Each and every time. As it will guess wrong at some point, and then the proverbial shit will hit the equally proverbial fan.

Some time ago I saw sowewhere someone (vague, huh?) saying that speech (or maybe that was handwriting) recognizing algorithms are at the moment around 90-95% accurate. That is, they get every 20th or at best every 10th word wrong. While this honestly is an excellent achievement (after all, both of those are very difficult things!), in practice this means that those aren't really usable at the moment. What good is a secretary whose work I have to proofread everything? None at all.

The same applies to compilers, but even more so. And better guess rate here is actually worse. If the compiler guesses the intent right 95% of the time it just means that my code will randomly fail approximately every 20 times (that is 20 compilations, not 20 program executions). So when you do some minor change elsewhere things suddenly break in unexpected ways as compiler ever so slightly alters its guesses. Not fun. And when compiler is 99,9% sure? Well, then the occasional hiccup will be really fun to figure out.

I once spent full day figuring out why the code suddenly stopped compiling. I had to go as far to examine full (C++) preprocessor outputs to find the reason, which turned out to be some bug in Visual Studio's preprocessor (might have been with precompiled headers, exact details escape me at the moment, as does the exact version of VS used; also, offending code was generated build-time by third-party code generator and intermediate .cpp files were not kept so this wasn't as easy as "diff two build snapshots to see what changed".)  Eventually I figured out that if some project headers were included in certain order in this one file, Visual Studio somehow dropped one (or maybe it was two, can't remember) from the build completely. "Fixing" it was simple (reorder headers) but it took a long time to get there. I imagine that figuring out compiler guessing your intent would be as fun as that specific wasted day.

On positive side, all this also means that my employment should be safe for many years to come - I don't expect artificial intelligences to be sufficiently smart to catch even close to all subtle issues in their instructions anytime soon, so real programmers will still be needed for long long time to tell computers exactly and explicitly what needs to be done.


Ei kommentteja:

Lähetä kommentti