Código absurdo o "cómo no escribir"

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.


Respuesta de 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

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 :)


All Articles