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.
“ ”
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. .
…
: ?
: ...
, . , , , .
, , 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 ++. , , .
- 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». .

, , :
- (« » , )
- CamelCase ( Python, C#)
- ,
- , if
- , ,
- 5 , > 16. . > = 17 ,
- ,
- (?!?)
- . Python, C++. .
, - ?
, . , . . 10- , junior . , - , .
, :
function foo(a) {
if (a) {
return transform(a);
}
return transform(a);
}
. , . … .
, . 3 , .
1 , .
/ bin / true - UNIX-, AT&T. true — , . ( , , while true ..) “” .
, AT&T, - , / bin / true AT&T UNIX. , , .
, , . AT&T ….
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 :)