Absurd code or "how not to write"

Most recently, I shared a post in which I collected funny comments in the source code and readers came in. And I decided, why not make a similar selection, only with crooked code? Who cares, welcome to cat.



Like the previous time, I was inspired for this post thanks to a very popular question on Quora, namely: What is the most absurd code you've ever seen? (Orig. What is the most absurd code you've ever seen?)


The question was posted a couple of years ago, but everyone continues to arrive there answers. I will share a few of them below.


Reply by Prashant Asthana


“ ”


MNC. , « Java» « ». , .


: , . , ?
: .


10 , :


int largestNumber = 0;
for (int i = 0; i < array.length - 1; i++) {
 largestNumber =
      array[i] > array[i+1] ?
          array[i] : array [i+1];
}

System.out.println(largestNumber);

, .


: , , , ?


5 .


: , .
: ?
: 1,2,3,4,5
( ): .


5 .


: , , . .


int largestNumber = 0;
for (int i = array.length - 1; i > 0; i--) {
 largestNumber =
      array[i] > array[i-1] ?
         array[i] : array [i-1];
}

System.out.println(largestNumber);

: 5,4,3,2,1. .



: ?
: ...


Thomas Breckinridge


, . , , , .


, , haht. - . , hahthahthaht hahtHahthaht, hahthahthaHt hahthAhthahT.


, , ,


if (hahthAhthahT >= hahthahthaht ) then hahtHahthaht(hahtHahtHaht,HAhtHahthaht);
else
 hahTHahthaht(hahtHahtHaht,HAhtHahthaht);

bitbucket.


:
, Borland Delphi/Object Pascal, , Pascal , . , C ++ Builder, , , haht. Borland , VisualBasic, Win32 API C / C ++. , , .


Alan Chavez


- JavaScript:


var obj = "{\"firstname\":\"" + firstName + "\",
\"lastname\":\"" + lastName + "\"}";
var res = JSON.parse(obj);
return res;

, JSON… JavaScript!
JSON JavaScript. .
, , , , : « ».


1 36 , , (O’Conelly), . 2 , .
«VP of Engineering». .


Ross Dickey



, , :


  1. (« » , )
  2. CamelCase ( Python, C#)
  3. ,
  4. , if
  5. , ,
  6. 5 , > 16. . > = 17 ,
  7. ,
  8. (?!?)
  9. . Python, C++. .

, - ?


Yoseph Radding


, . , . . 10- , junior . , - , .


, :


function foo(a) {
   if (a) {
       return transform(a);
   }
   return transform(a);
}

. , . … .
, . 3 , .


1 , .


Ryan Lam


#!/usr/bin/sh
#  Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
#  All Rights Reserved

#  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#  The copyright notice above does not evidence any
#  actual or intended publication of such source code.

#ident  "@(#)true.sh  1.6  93/01/11 SMI"  /* SVr4.0 1.4  */

/ bin / true - UNIX-, AT&T. true — , . ( , , while true ..) “” .


, AT&T, - , / bin / true AT&T UNIX. , , .


, , . AT&T ….


Khaled Bakhit


rows= SELECT * FROM users
int count= 0
for each row in rows
   count= count + 1
return count

API .


( ), select . , , .


, !


, ( , ). Count, .


rows= SELECT * FROM users
int count= 0
for each row in rows
  count = count + 1

checkCount= SELECT count(*) FROM users

if count != checkCount
   throw Error
return count

This code fragment often caused exceptions, because by the time the first counter was executed, the table was filled with more records, giving the second counter a different value ...


True story. I wish it were not so.


Conclusion


Read more answers in the original here . Well, by tradition, share your options for the absurd / stupid / strange code that you met in your practice. I think reading will be interesting not only to me, but to everyone who stumbles upon this article :)


All Articles