1. Лучший говнокод

    В номинации:
    За время:
  2. Java / Говнокод #11381

    +72

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    public abstract class SomeActivity extends Activity implements SomeEventListener {
    
        @Override
        protected void onResume() {
            super.onResume();
            application.addSomeListener(this);
        }
    
        @Override
        protected void onPause() {
            application.removeSomeListener(this);
            super.onPause();
        }

    В дополнение к #11379
    Вопрос пользователю нужно задать поверх любой нашей активити...

    rat4, 08 Июля 2012

    Комментарии (1)
  3. PHP / Говнокод #11299

    +72

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public function isAdmin() {
            $admins = Model::factory('User')->where('access_level_id', 1)->find_many();
            $ids = array();
            foreach($admins as $admin) {
                $ids[]= $admin->id;
            }
            return in_array($this->id, $ids) ? true : false;
        }

    Метод проверки на админе из модели пользователей. Не, ну а чо.

    mr.The, 26 Июня 2012

    Комментарии (21)
  4. Java / Говнокод #10596

    +72

    1. 1
    2. 2
    Long count = ((Long) q.getSingleResult()).longValue();
    int pages = ((Long) (count / rowsPerPage)).intValue();

    конвертировали-конвертировали, и выконвертировали

    Lure Of Chaos, 06 Июня 2012

    Комментарии (3)
  5. Java / Говнокод #10588

    +72

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (style == null || (style != null && !style.isEnabled())) {
        throw new IllegalStateException(); 
    }
    if (style != null) {
        do something . . .
    }

    mychka, 05 Июня 2012

    Комментарии (2)
  6. Java / Говнокод #10396

    +72

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    public AllianceEntity getByMember(BigInteger dcgId) {
            for (AllianceEntity alliance : getAll()) {
                if (String.valueOf(alliance.getAdminDcgId()).equals(String.valueOf(dcgId))) {
                    return alliance;
                }
                for (BigInteger memberDcgId : alliance.getMembersAsList()) {
                    if (String.valueOf(memberDcgId).equals(String.valueOf(dcgId))) {
                        return alliance;
                    }
                }
                for (BigInteger officerDcgId : alliance.getOfficersAsList()) {
                    if (String.valueOf(officerDcgId).equals(String.valueOf(dcgId))) {
                        return alliance;
                    }
                }
            }
            return null;
        }

    все айдишники BigInteger..

    iliakot, 29 Мая 2012

    Комментарии (0)
  7. PHP / Говнокод #10364

    +72

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    //1. файл
    ...
    else if ($elem->tagName == "Error") {
    		$errorCode = trim($elem->getElementsByTagName("Code")->item(0)->textContent);
    		$errorText = trim($elem->getElementsByTagName("Text")->item(0)->textContent);
    
    		var_dump('Fuck!!! Some Error:',$errorCode,$errorText);						
    }
    ...
    
    //2. файл, после получения результатов
    ...
    if(empty($result)){	
    	var_dump($sql);
    	die('Page fucking dead!!!!!');
    }
    ...
    
    //2. файл, 
    ...
    if(!file_exists($filePath)){	
    	var_dump('No file found???!!! Where if fucking CLASS file???!!!', $filePath);
    	return false;
    }
    ...
    
    //3. файл, 
    ...
    if (empty($fields['id'])){
    	var_dump('AAAAAAAAA. No ID again!!!', $fields, $sql);
    	return false;
    }
    ...
    
    //4. файл, 
    ...
    if (!$error){
    	if($this->debug)var_dump('Yeeeees!!! Work fine ^_^');
    	return true;
    }
    ...

    Наткнулся на один проектик. Не совсем говнокод, но программер был видать оочень емоциональный :)

    Edd, 25 Мая 2012

    Комментарии (5)
  8. PHP / Говнокод #10285

    +72

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    /* Данные пользователя*/
    $fio=$_POST['fio'];
    $sex=$_POST['sex'];
    $sdate=$_POST['sdate'];
    $city=$_POST['city'];
    $age=$_POST['age'];
    $hage=$_POST['hage'];
    $cage=$_POST['cage'];
    $page=$_POST['page'];
    $stime=$_POST['stime'];
    $ip=$_POST['ip'];
    /* Вопросы*/
    $a1=$_POST['a1'];
    $a1b1=$_POST['1a1'];
    $a1b2=$_POST['1a2'];
    $a1b3=$_POST['1a3'];
    $a1b4=$_POST['1a4'];
    $com1=$_POST['com1'];
    $a2=$_POST['a2'];
    $a2b1=$_POST['2a1'];
    $a2b2=$_POST['2a2'];
    $com2=$_POST['com2'];
    $a3=$_POST['a3'];
    $b1a1=$_POST['b1a1'];
    $b1a2=$_POST['b1a2'];
    $b1a3=$_POST['b1a3'];
    $a4=$_POST['a4'];
    $a3b1=$_POST['3a1'];
    $a3b2=$_POST['3a2'];
    $a3b3=$_POST['3a3'];
    $a3b4=$_POST['3a4'];
    $a3b5=$_POST['3a5'];
    $a3b6=$_POST['3a6'];
    $a3b7=$_POST['3a7'];
    $a3b8=$_POST['3a8'];
    $a3b9=$_POST['3a9'];
    $a3b10=$_POST['3a10'];
    $com3=$_POST['com3'];
    $a5=$_POST['a5'];
    $b2a1=$_POST['b2a1'];
    $b2a2=$_POST['b2a2'];
    $b2a3=$_POST['b2a3'];
    $a6=$_POST['a6'];
    $a4b1=$_POST['4a1'];
    $a4b2=$_POST['4a2'];
    $a4b3=$_POST['4a3'];
    $a4b4=$_POST['4a4'];
    $a4b5=$_POST['4a5'];
    $a4b6=$_POST['4a6'];
    $a4b7=$_POST['4a7'];
    $com4=$_POST['com4'];
    $a7=$_POST['a7'];
    $b3a1=$_POST['b3a1'];
    $b3a2=$_POST['b3a2'];
    $b3a3=$_POST['b3a3'];
    $a8=$_POST['a8'];
    $a5b1=$_POST['5a1'];
    $a5b2=$_POST['5a2'];
    $a5b3=$_POST['5a3'];
    $a5b4=$_POST['5a4'];
    $a5b5=$_POST['5a5'];
    $a5b6=$_POST['5a6'];
    $a5b7=$_POST['5a7'];
    $a5b8=$_POST['5a8'];
    $a5b9=$_POST['5a9'];
    $a5b10=$_POST['5a10'];
    $a5b11=$_POST['5a11'];
    $com5=$_POST['com5'];
    $a9=$_POST['a9'];
    $a6b1=$_POST['6a1'];
    $a6b2=$_POST['6a2'];
    $a6b3=$_POST['6a3'];
    $a6b4=$_POST['6a4'];
    $a6b5=$_POST['6a5'];
    $a6b6=$_POST['6a6'];
    $a6b7=$_POST['6a7'];
    $a6b8=$_POST['6a8'];
    $com6=$_POST['com6'];
    
    echo "<CENTER>";
    echo "Привет, ".$_POST['fio'];
    echo "<BR><BR>";
    echo "Спасибо за ваш интерес.<BR><BR>";
    
    
    ....

    нашли в прокте вот такое извращение :)

    olegpro, 16 Мая 2012

    Комментарии (8)
  9. Java / Говнокод #10246

    +72

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    final String sqlString=
    					" select distinct 1 "+
    					" , c_rep.card_id as rep_id "+
    					" , av_rep_xml.long_binary_value as rep_xml "+
    					" , av_sname_nm.string_value as name "+
    					" , av_c_date.date_value as date \n"+
    					" from	card c_res \n"+
    					" 	join 	attribute_value av_res_rep on (av_res_rep.card_id = c_res.card_id and av_res_rep.attribute_code = 'JBR_RIMP_REPORT') \n"+
    					" 	join	attribute_value av_res_exec on (av_res_exec.card_id = c_res.card_id and av_res_exec.attribute_code = 'JBR_INFD_EXEC_LINK') \n"+
    					" 	join 	card c_rep on (c_rep.card_id = av_res_rep.number_value ) \n"+
    					" 	left outer join attribute_value av_rep_xml on (av_rep_xml.card_id = c_rep.card_id and av_rep_xml.attribute_code = 'ADMIN_702354') \n"+
    					" 	left outer join attribute_value av_c_date on (av_c_date.card_id = c_rep.card_id and av_c_date.attribute_code = 'CREATED') \n"+
    					" 	left outer join	attribute_value av_rep_exec on (av_rep_exec.card_id = c_rep.card_id and av_rep_exec.attribute_code ='ADMIN_702335') \n"+
    					" 	left outer join	person person_card on (person_card.person_id=av_rep_exec.number_value) \n"+
    					" 	left outer join attribute_value av_sname_nm on (av_sname_nm.card_id = person_card.card_id and av_sname_nm.attribute_code = 'JBR_PERS_SNAME_NM') \n"+
    					" 	left outer join attribute_value av_on_control on ( av_on_control.attribute_code = 'JBR_TCON_ONCONT' and av_on_control.card_id = c_res.card_id) \n"+
    					" where	c_res.card_id = " + sResId+ "\n"+
    					" 	and av_res_exec.number_value = av_rep_exec.number_value \n"+
    					" 	and av_on_control.value_id=1449 \n"+
    					" 	and c_res.status_id in (103, 206) \n"+
    
    					// UNION
    					" UNION select 51 \n"+
    					" , c_rep.card_id as rep_id \n"+
    					" , av_rep_xml.long_binary_value as rep_xml \n"+
    					" , av_sname_nm.string_value as name \n"+
    					" , av_c_date.date_value as date \n"+
    					" from card c_prnt \n"+
    					" 	left outer join attribute_value av_res on ( av_res.attribute_code = 'JBR_IMPL_RESOLUT' and av_res.card_id = c_prnt.card_id) "+
    					" 	left outer join card c_res on (c_res.card_id=av_res.number_value)"+
    					" 	join 	attribute_value av_res_rep on (av_res_rep.card_id = c_res.card_id and av_res_rep.attribute_code = 'JBR_RIMP_REPORT') "+
    					" 	join	attribute_value av_res_exec on (av_res_exec.card_id = c_res.card_id and av_res_exec.attribute_code = 'JBR_INFD_EXEC_LINK') "+
    					" 	join 	card c_rep on (c_rep.card_id = av_res_rep.number_value ) "+
    					" 	left outer join attribute_value av_rep_xml on (av_rep_xml.card_id = c_rep.card_id and av_rep_xml.attribute_code = 'ADMIN_702354') "+
    					" 	left outer join attribute_value av_c_date on (av_c_date.card_id = c_rep.card_id and av_c_date.attribute_code = 'CREATED') "+
    					" 	left outer join	attribute_value av_rep_exec on (av_rep_exec.card_id = c_rep.card_id and av_rep_exec.attribute_code = 'ADMIN_702335') "+
    					" 	left outer join	person person_card on (person_card.person_id=av_rep_exec.number_value) "+
    					" 	left outer join attribute_value av_sname_nm on (av_sname_nm.card_id = person_card.card_id and av_sname_nm.attribute_code = 'JBR_PERS_SNAME_NM') "+
    					" 	left outer join attribute_value av_on_control on ( av_on_control.attribute_code = 'JBR_TCON_ONCONT' and av_on_control.card_id = c_res.card_id)  "+
    					" where "+
    					" 	c_prnt.card_id = "+ sResId+ "\n"+
    					" 	and c_prnt.template_id <> 324 \n"+
    					" 	and av_res_exec.number_value = av_rep_exec.number_value \n"+
    					" 	and av_on_control.value_id=1449 \n"+
    					" 	and c_res.status_id in (103, 206) \n"+
    	
    .... и еще 8 UNION, куча строчек в том же стиле и с тем же смыслом

    Формирование SQL запроса в методе, который возвращает строковое представление хода исполнения поручения (кто сделал, что сделал, когда и в какой последовательности). Сам метод, если кому интересно дергается из Jasper report.

    Мало того, что запросик имеет длину 250 строк кода (большая часть которых копи/паст с небольшими изменениями), так он ещё и возвращает полную ахинею вместо того что нужно. Чего хотел сказать автор - теперь уже не узнать...

    amberLord, 11 Мая 2012

    Комментарии (12)
  10. Pascal / Говнокод #10064

    +72

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    const 
    zn1 = #60; { < }   
    zn2 = #62; { > } 
    
    function EnCrypt(ds: string): string;
      var 
    k,l,m: string; 
    i,b,g: integer; 
    t: char;
       function Lvs(ds: byte): string;
       begin
        case ds of 
       Byte(zn1): Result:= zn1+zn2;
       Byte(zn2): Result:= zn2+zn1;
             0: if Random(2)=0 then  Result:= zn1+zn1 
                 else Result:= zn2+zn2;
               else 
                 Result:= Chr(ds);end;
       end;
      begin
       if length(ds)=0 then Exit; 
       Randomize;  k:=''; m:='';  b:=1;
     for i:=1 to RandomRange(5,16) do 
      k:= k+Chr(RandomRange(1,256));
       for i:=1 to Length(ds) do  begin 
    g:= Byte(ds[i])xor Byte(k[b]);
       l:= Lvs(g); t:= k[b];
    if i<= Length(k) then m:= m+t+l else m:=m+l;
    Inc(b);
       if b>Length(k) then b:= 1; 
      end; 
    l:= Chr(Length(k))+m;
       for  i:=1 to Length(l) do begin 
    b:= Byte(l[I]) xor i;k:= Lvs(b);
       Result:= Result+k; 
    end;
      end;
    
     function DeCrypt(ds: string): string;
      var 
    k,c,l,n: string; 
    i,b,m: integer; 
    d: boolean;
       function Svl(ds: string; ts: integer): char;
       var t: byte;
       begin
        t:=Byte(ds[1]);
        if ds=zn1+zn2 then t:=Byte(zn1);
        if ds=zn2+zn1 then t:=Byte(zn2);
        if(ds=zn1+zn1) or (ds=zn2+zn2) then t:= 0;
       Result:=Chr(Byte(t xor ts));
       end;
      begin
       if length(ds)=0 then Exit;
     b:=1; i:=1; n:='';
       while i<=Length(ds) do begin c:= ds[i];
       if (ds[i]=zn1)or(ds[i]=zn2)then begin 
    c:=ds[i]+ds[i+1]; Inc(i); end;
       Inc(i);
     n:= n+Svl(c,b); 
    Inc(b); 
    end; c:=''; k:=''; b:=1; i:=1; 
    d:=false;
    m:=Byte(n[1]); 
    Delete(n,1,1);
       while i<=Length(n)do begin 
    if b<=m*2 then begin if d then begin 
    l:=n[i];
      if (n[i]=zn1) or (n[i]=zn2) then 
    begin 
        l:= n[i]+n[i+1]; Inc(i); 
    end;
       c:=c+l; 
    Inc(b);
    d:=false; 
    end else 
    begin 
    k:=k+n[i]; d:=true; Inc(b); 
    end;
       end else begin 
    l:= n[i]; 
    if (n[i]=zn1) or (n[i]=zn2) then 
    begin   l:= n[i]+n[i+1]; Inc(i); end;  
    c:=c+l; end;
     Inc(i); end;
       if length(c)=0 then Exit;
    i:=1;b:=1; 
    while i<=Length(c)do begin 
    l:=c[i];
       if (c[i] = zn1) or (c[i] = zn2) then 
    begin 
    l:= c[i] + c[i+1]; Inc(i); 
    end;
       Inc(i);
    Result:= Result + Svl(l, Byte(k[b]));
    Inc(b);
    if b>Length(k)then b:=1;
       end;
      end;

    В очень далёком 99м году была совершена попытка шифровать и дешифровать пароли пользователей простым ХОР-замесом. Тогда такой способ казался идеальным и оригинальным :) Но посмотрите, если руки не оттуда откуда надо растут, как же можно извратиться, чистый говнокод! До сих пор им пользуюсь, немного. Интересно, ктонить догадается, зачем здесь константные знаки используются?

    Alegun, 27 Апреля 2012

    Комментарии (7)
  11. Java / Говнокод #9985

    +72

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    //сложение двух векторов
    	public Vector sum(Vector vector) throws Exception {
    		if (vectorSize != vector.vectorSize) {
    			try {
    				throw new Exception("different size");
    			} catch (Exception e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    		Vector result = new Vector(vectorSize);
    		for (int i = 0; i < vectorSize; ++i) {
    			result.vector[i] = this.vector[i] + vector.vector[i];
    		}
    		return result;
    	}

    Jk, 19 Апреля 2012

    Комментарии (11)