3 ms·
Sure, but as John Carmack has said, if the compiler allows something, it will end up in the codebase once it gets sufficiently large. I work for a brand-name b
by tombert 8y ago
Sure, but as John Carmack has said, if the compiler allows something, it will end up in the codebase once it gets sufficiently large.
I work for a brand-name big company (I won't mention it here but I'll tell you if you email me) that hires incredibly talented engineers that are a lot smarter than me. The codebase I work on is around ~20 million lines of Java, and I've seen stuff in there that is so incredibly gross that a compsci professor would write "see me after class" if you submitted it.
Example: I once saw a piece of code doing this:
do {
// doing stuff
} while (false)
It took me about 10 minutes of digging into the code to realize that the person who wrote this was doing this so that they could add a `break` in there as sort of a makeshift `goto` so they could early-exit and skip all the rest of the stuff in the block. Needless to say, I was horrified.
Why is it that incredibly talented engineers are writing awful code like that? It's certainly not incompetence; what almost certainly happened was that there was some kind of time-crunch, and the dev (understandably) felt the need to cheat. This is a direct consequence of the compiler allowing a bad design.
- Const-me 8y agoThat loop is totally fine. I wrote it many times in C#, C and C++, and I saw it many more times in other people’s code. Microsoft DDK sample: https://github.com/Microsoft/Windows-driver-samples/blob/master/avstream/samplemft0/Mft0.cpp https://github.com/Microsoft/Windows-driver-samples/blob/mas... Microsoft MediaFoundation sample: https://github.com/Microsoft/Windows-classic-samples/blob/master/Samples/DX11VideoRenderer/cpp/MediaSink.cpp https://github.com/Microsoft/Windows-classic-samples/blob/ma... OpenSSL: https://github.com/openssl/openssl/blob/master/crypto/sha/sha256.c https://github.com/openssl/openssl/blob/master/crypto/sha/sh... And many others. Just because code looks unfamiliar doesn’t mean it’s something wrong with the code.