Programmers, here are the most absurd codes that you may have ever seen
Hardcore programmers will say that coding is an art or science. While learning to code is hard, tedious and excruciating, it is the end result that counts. There are millions of new programs being written every day so that our lives will be that much easier. But sometimes programmers write that one code which has no explanation. Rather it borders on absurdity.
Today, we look at some of these weirdest codes ever written. The way these absurd codes are written, only the programmer who wrote this program may be able to explain why it is so.
World’s most absurd codes ever written!
รmile PerronWeb developer and CS graduate found thisย a function which ran faster than any other function or method. It was named _addslashes, so when going through the code, youโre expecting it to be some kind of improved version of the addslashes function. And thatโs where you would be wrong! No wonder there were issues with the database updates/inserts in this part of the code. Oh, and needless to say, those werenโt prepared or sanitized queries. And there wasnโt much (if any) validation, either
Software engineer,ย Fouad Elia Kada who found this code says that he hasย what the guy who wrote this code had in mind or what the code does.
Developer, Andrew Philips explains this code.ย For those unfamiliar with C languages, this code scans a character array (string) looking for an element whose value is 0 (or \0 or the NULL value) and returns the index of that element, which is defined to be the end of the string. The function strlen requires that the character array passed in has a NULL terminator. The rest of the line takes the location with a Zero and assigns Zero to it.
Looking for a NULL terminator and then setting the location to the value it already contains does nothing save risking a segmentation fault because the string may not have been terminated properly, which would cause strlen to wander off the end and eventually return an index outside the allocated boundary of the array, and assigning zero to a random memory location could be out of process memory bounds or modify another, random data structure with unpredictable and incorrect results. The problems are legion and boundless.
If the string was conforming, at best it wastes time and turns electricity into heat (microprocessor) while doing no useful work.
Software engineer,ย Patrick Minton who found this code says he is still pulling his hair out interpreting this one.ย The dreaded IF NOT / ELSE block, combined with the fact that the variable itself is true when it represents a negative stateโฆ.*pulls hair out*
Web developer Rory Glasgow found this code in a PHP script several years ago. He says he is surprised, the programmer who did this used so many variables when the same output can be obtained using simpleย $output = strtoupper($input);
Software developer,ย Anirban Ghoshal found a bug which he was fascinated in an application designed to perform a sophisticated audit on a large array of integer values for consistency. The audit would attempt to skip values in that array that fell within a certain range (a,b)(a,b). For this range, the audit would simply return success without performing any kind of validation on the values. The person who wrote the code according to above image.
In the above code, within the if check, instead of the logical AND operator, the programmer used the bitwise OR, which made the condition true for every value in the array. It was years before somebody noticed the flaw. Apparently, everyone was pleased as punch that the audit never failed because then the program that populated the array would be pretty much the perfect piece of code ever written in the history of that organization.
Developerย Steve Savitzky says absurd code is one of his all-time favorite sorting algorithm, given in pseudo-code.ย The average complexity is O(n!). The worst-case complexity is infinite. You can improve it by deterministically generating all permutations in sequence, but that takes all the fun out of it.
Software engineer,ย Grigory Yakushev who found this code says that the code was actually correct. They noticed the mistake when the method started to show up in profiling.
Software engineer,ย Christopher Burke says that this is the weirdest code he has noticed. He says that this code is surprisingly common. He found another variant of itย in a code review. “I knew p wasnโt volatile. I asked the coder if heโd overloaded the โ=โ operator; he said no. I asked why heโd written the code this way, and he said, โJust cleaning up some unused pointers.โ Another reviewer wrote, โโฆyou donโt need to check that p is non-null, just set it null.โ
The programmer simplified the code before finalizing it.”
Above are some of weirdest codes written by programmers. If you have found any such eerie code that left you splitting your hair, kindly note it down in comments section so that we can make a part 2 of this article.