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!
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.