Más recientemente, compartí una publicación en la que recopilaba comentarios divertidos en el código fuente y entraban lectores. Y decidí, ¿por qué no hacer una selección similar, solo con código torcido? A quién le importa, bienvenido al gato.
Como la vez anterior, me inspiré para esta publicación gracias a una pregunta muy popular sobre Quora, a saber: ¿Cuál es el código más absurdo que hayas visto? (Orig. ¿Cuál es el código más absurdo que hayas visto?)
La pregunta fue publicada hace un par de años, pero todos continúan llegando allí respuestas. Compartiré algunos de ellos a continuación.
“ ”
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
Este fragmento de código a menudo causaba excepciones, porque cuando se ejecutó el primer contador, la tabla se llenó con más registros, dando al segundo contador un valor diferente ...
Historia verdadera. Desearía que no fuera así.
Conclusión
Lea más respuestas en el original aquí . Bueno, por tradición, comparta sus opciones para el código absurdo / estúpido / extraño que ha encontrado en su práctica. Creo que leer será interesante no solo para mí, sino para todos los que se topan con este artículo :)