Código absurdo ou "como não escrever"

Mais recentemente, compartilhei uma postagem na qual coletei comentários engraçados no código fonte e os leitores entraram. E eu decidi, por que não fazer uma seleção semelhante, apenas com um código torto? Quem se importa, bem-vindo ao gato.



Como na época anterior, fui inspirado para este post graças a uma pergunta muito popular no Quora, a saber: Qual é o código mais absurdo que você já viu? (Orig. Qual é o código mais absurdo que você já viu?)


A pergunta foi publicada há alguns anos, mas todos continuam chegando lá. Vou compartilhar alguns deles abaixo.


Responder por 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

Esse fragmento de código geralmente causava exceções porque, quando o primeiro contador foi executado, a tabela estava preenchida com mais registros, dando ao segundo contador um valor diferente ...


História real. Eu gostaria que não fosse assim.


Conclusão


Leia mais respostas no original aqui . Bem, por tradição, compartilhe suas opções para o código absurdo / estúpido / estranho que você conheceu em sua prática. Acho que a leitura será interessante não apenas para mim, mas para todos que se depararem com este artigo :)


All Articles