1. PHP / Говнокод #8740

    +157

    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
    function &_static($name = null, $value = null, $unsetVal = false) {
      static $data = array();
      $null = null;
      if (is_array($name)) {
        $data = $name;
        return $null;
      }
      $state = 0;
      $args = array($name, $value, $unsetVal);
      while (count($args)) {
        $arg = array_shift($args);
        switch ($state) {
          case 0:
            if ($arg === null) {
              $state = 8;
            }
            elseif ($arg !== null) {
              $state = 1;
            }
            else {
              throw new \InvalidArgumentException();
            }
            break;
    
          case 1:
            if ($arg === null) {
              $state = 5;
            }
            elseif ($arg !== null) {
              $state = 2;
            }
            else {
              throw new \InvalidArgumentException();
            }
            break;
    
          case 2:
            if ($arg === true) {
              $data[$name] = $value; // $name, $value, true - overwrite saved value and return reference on it.
              return $data[$name];
            }
            elseif ($arg === false) {
              if (!array_key_exists($name, $data)) {
                $data[$name] = $value;
              }
              return $data[$name]; // $name, $value, false - save value if not exist, return reference on stored value.
            }
            else {
              throw new \InvalidArgumentException();
            }
    
          case 5:
            if ($arg === false) {
              if (!array_key_exists($name, $data)) {
                $data[$name] = $value; // $name, null, false, - initialize var if not exist, return reference on stored value.
              }
              return $data[$name];
            }
            elseif ($arg === true) {
              $data[$name] = $value; // $name, $value, true - overwrite saved value and return reference on it.
              return $data[$name]; // $name, null, true - overwrite saved value and return reference on it.
            }
            else {
              throw new \InvalidArgumentException();
            }
            break;
    
          case 8:
            if ($arg === null) {
              continue;
            }
            if ($arg === true) {
              $data = array(); // null, null, true - unset all
              break 2;
            }
            elseif ($arg === false) {
              return $data; // null, null, false - return all
            }
            else {
              throw new \InvalidArgumentException();
            }
    
          default:
            throw new \RuntimeException('Unknown state.');
        }
      }
      return $null;
    }

    Как сделать глобальные переменные своими руками?
    Как сделать ветвление когда под рукой не оказалось if, зато есть while и switch?

    sectus, 05 Декабря 2011

    Комментарии (33)
  2. PHP / Говнокод #8722

    +177

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    "
    <td><span>\".setDiskont2(\$data[price]*{$as_Quantity}, $current_site[Skidka], \$data[Discount]).\"</span></td>
    <th></th>
    </tr>
      ")." 
      ".as_if($totalsum+=as_query("SELECT price FROM Data".$as_ObjectID." WHERE Data_ID=$as_ItemID","\$data[price]")*$as_Quantity*$as_Discount,"")."
    ")."

    Оцените.
    Этот кусок кода хранится в поле таблицы бд, в котором хранится кусок шаблона формы корзины интернет-магазина.
    Функция на шестой строке выводит общую сумму заказа при eval.
    У меня ушло более двух часов, чтобы розыскать логику внутри семикратной (! я не шучу) вложенности include_once, чтобы в итоге понять, что запрос который я искал хранится в самой бд, причем не просто храниться, а хранится внутри бд, внутри php который хранится внутри html... Сам Доминик Кобб позавидовал бы степени вложенности моих кошмаров %)

    antongorodezkiy, 04 Декабря 2011

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

    +75

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if(false || DEBUG)
        {
          System.out.print("analysis: "+Integer.toBinaryString(analysis));
          System.out.println(", "+WalkerFactory.getAnalysisString(analysis));
        }

    Вычурный способ делать комментарии. Пример может и боян, но зато где: в исходниках API Android 2.2 Froyo.

    google-moogle, 04 Декабря 2011

    Комментарии (35)
  4. PHP / Говнокод #8720

    +159

    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
    $t2 = db_query("SELECT
          			COUNT(*)
      			FROM
         			order_delivery_offers AS odf,
         			uc_orders AS uo
      			WHERE
         			odf.order_id = uo.order_id AND
         			uo.uid = $uid AND
         			uo.order_status = 'accepted' AND
         			odf.status = 'accepted' AND
         			odf.visible = 1 AND
         			odf.active = 1
      			GROUP BY odf.order_id");
      $count_rows2 = 0;
      while ($r2 = db_fetch_array($t2)){
    		$count_rows2++;
      }

    Подсчет количества записей в запросе.

    beertudam, 04 Декабря 2011

    Комментарии (4)
  5. C++ / Говнокод #8719

    +168

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    case IDC_LED1_ZERO:
    				if (::IsDlgButtonChecked (hWnd,IDC_LED1_ZERO) )
    				{
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ANYSPEED) )
    						::CheckDlgButton(hWnd,IDC_LED1_ANYSPEED,0);
    
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_POSITION) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_POSITION) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_POSITION) )
    						::CheckDlgButton(hWnd,IDC_LED1_POSITION,0);
    
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
    						::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
    
    					::CheckDlgButton(hWnd,IDC_LED1_TURN_UNDER,0);
    					::CheckDlgButton(hWnd,IDC_LED2_ZERO,0);
    					::CheckDlgButton(hWnd,IDC_LED3_ZERO,0);
    					::CheckDlgButton(hWnd,IDC_LED4_ZERO,0);
    
    				}
    		break;
    		case IDC_LED1_ANYSPEED:
    				if (::IsDlgButtonChecked (hWnd,IDC_LED1_ANYSPEED) )
    				{
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ZERO) )
    						::CheckDlgButton(hWnd,IDC_LED1_ZERO,0);
    
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_POSITION) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_POSITION) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_POSITION) )
    						::CheckDlgButton(hWnd,IDC_LED1_POSITION,0);
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
    						::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
    
    					::CheckDlgButton(hWnd,IDC_LED1_TURN_UNDER,0);
    					::CheckDlgButton(hWnd,IDC_LED2_ANYSPEED,0);
    					::CheckDlgButton(hWnd,IDC_LED3_ANYSPEED,0);
    					::CheckDlgButton(hWnd,IDC_LED4_ANYSPEED,0);
    				}
    		break;
    		case IDC_LED1_POSITION:
    				if (::IsDlgButtonChecked (hWnd,IDC_LED1_POSITION) )
    				{
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ZERO) )
    						::CheckDlgButton(hWnd,IDC_LED1_ZERO,0);
    
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ANYSPEED) )
    						::CheckDlgButton(hWnd,IDC_LED1_ANYSPEED,0);
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
    						::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
    
    					::CheckDlgButton(hWnd,IDC_LED1_TURN_UNDER,0);
    					::CheckDlgButton(hWnd,IDC_LED2_POSITION,0);
    					::CheckDlgButton(hWnd,IDC_LED3_POSITION,0);
    					::CheckDlgButton(hWnd,IDC_LED4_POSITION,0);
    
    				}
    		break;
    		case IDC_LED1_TURN_UNDER:
    				if (::IsDlgButtonChecked (hWnd,IDC_LED1_TURN_UNDER) )
    				{
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ZERO) )
    						::CheckDlgButton(hWnd,IDC_LED1_ZERO,0);
    
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ANYSPEED) )
    						::CheckDlgButton(hWnd,IDC_LED1_ANYSPEED,0);
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
    						::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
    
    					::CheckDlgButton(hWnd,IDC_LED1_POSITION,0);
    					::CheckDlgButton(hWnd,IDC_LED2_TURN_UNDER,0);
    					::CheckDlgButton(hWnd,IDC_LED3_TURN_UNDER,0);
    					::CheckDlgButton(hWnd,IDC_LED4_TURN_UNDER,0);
    				}

    Понадобилось добавить ещё один чек бокс. Зашёл в обработчик - а там такое. И это только начало, всё не поместилось. Чтобы представить масштабы скажу, что чекбоксов 16..., я должен добавить ещё 4.

    slavap, 04 Декабря 2011

    Комментарии (4)
  6. Pascal / Говнокод #8718

    +112

    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
    {...}
    type
    a=(
    january,
    february,
    march,
    {--------------}
    april,
    may,
    june,
    {--------------}
    jule,
    august,
    september,
    {--------------}
    october,
    november,
    december
                 );
    b=(
    seаson1,
    seаson2,
    seаson3,
    seаson4
               );
    c=(
    winter,
    spring,
    summer,
    autumn
              );
    {...}
    function d(e:a):b;
             begin
                  case e of
                           january,
                           february,
                           march
                                     :d:=seаson1;
                           april,
                           may,
                           june
                                     :d:=seаson2;
                           jule,
                           august,
                           september
                                     :d:=seаson3;
                           october,
                           november,
                           december
                                     :d:=seаson4
                  end
             end;
    function f(g:a):c;
             begin
                  case g of
                           december,
                           january,
                           february
                                      :f:=winter;
                           march,
                           may,
                           april
                                      :f:=spring;
                           june,
                           jule,
                           august
                                      :f:=summer;
                           september,
                           october,
                           november
                                      :f:=autumn
                  end
             end;
    begin
    {...}
    end.

    Сделал на этой неделе в первом часу ночи.

    dos_, 04 Декабря 2011

    Комментарии (30)
  7. C++ / Говнокод #8717

    +1000

    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
    bool __fastcall TItsString::operator == (const char* sVal) const
    {
      bool Empty1 = ((FStringValue == NULL) || (FStringValue[0] == 0));
      bool Empty2 = ((sVal == NULL) || (sVal[0] == 0));
      if (Empty1 && Empty2) return true;
      if (Empty1 || Empty2) return false;
      int i,j,k;
      for(i=0; FStringValue[i] && (GET_LOWER_CHAR(FStringValue[i]) == GET_LOWER_CHAR(sVal[i])); i++);
      if ((FStringValue[i] == 0) && (sVal[i] == 0)) return true;
      j=i; k=i;
      if (sVal[k] == 0)  for(; FStringValue[i] == 0x20; i++);
      if (FStringValue[k] == 0) for(; sVal[j] == 0x20; j++);
      if ((FStringValue[i] == 0) && (sVal[j] == 0)) return true;
      return false;
    }

    Try, 03 Декабря 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    const ORDER_FUNC_ARGS   = '$a, $b';
    	const ORDER_FUNC_LOGIC  = '$a=strlen($a);$b=strlen($b);return$a==$b?0:($a<$b?1:-1);';
    // а дальше в одном из методов
    		$this->_userAgents 	= array_keys($browsers);
    		usort(
    			$this->_userAgents,
    			create_function(self::ORDER_FUNC_ARGS, self::ORDER_FUNC_LOGIC)
    		);

    Для меня это странно выглядит

    LiteError, 03 Декабря 2011

    Комментарии (0)
  9. ActionScript / Говнокод #8714

    −111

    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
    public class MonstrGrafic extends ModulINT {
    		var data:XML;
    		var colors:Array = new Array(
    			'0x008080',
    			'0x800080',
    			'0xccffcc',
    			'0x00ffff',
    			'0x800000',
    			'0x0000ff',
    			'0x00ccff',
    			'0xccffff',
    			'0xffff00',
    			'0xffff99',
    			'0x000080',
    			'0xff00ff'
    		);
    		var ListTime:Array = new Array(
    			"08:00:00 - 08:15:00",
    			"08:15:00 - 08:30:00",
    			"08:30:00 - 08:45:00",
    			"08:45:00 - 09:00:00",
    			"09:00:00 - 09:15:00",
    			"09:15:00 - 09:30:00",
    			"09:30:00 - 09:45:00",
    			"09:45:00 - 10:00:00",
    			"10:00:00 - 10:15:00",
    			"10:15:00 - 10:30:00",
    			"10:30:00 - 10:45:00",
    			"10:45:00 - 11:00:00",
    			"11:00:00 - 11:15:00",
    			"11:15:00 - 11:30:00",
    			"11:30:00 - 11:45:00",
    			"11:45:00 - 12:00:00",
    			"12:00:00 - 12:15:00",
    			"12:15:00 - 12:30:00",
    			"12:30:00 - 12:45:00",
    			"12:45:00 - 13:00:00",
    			"13:00:00 - 13:15:00",
    			"13:15:00 - 13:30:00",
    			"13:30:00 - 13:45:00",
    			"13:45:00 - 14:00:00",
    			"14:00:00 - 14:15:00",
    			"14:15:00 - 14:30:00",
    			"14:30:00 - 14:45:00",
    			"14:45:00 - 15:00:00",
    			"15:00:00 - 15:15:00",
    			"15:15:00 - 15:30:00",
    			"15:30:00 - 15:45:00",
    			"15:45:00 - 16:00:00",
    			"16:00:00 - 16:15:00",
    			"16:15:00 - 16:30:00",
    			"16:30:00 - 16:45:00",
    			"16:45:00 - 17:00:00",
    			"17:00:00 - 17:15:00",
    			"17:15:00 - 17:30:00",
    			"17:30:00 - 17:45:00",
    			"17:45:00 - 18:00:00",
    			"18:00:00 - 18:15:00",
    			"18:15:00 - 18:30:00",
    			"18:30:00 - 18:45:00",
    			"18:45:00 - 19:00:00",
    			"19:00:00 - 19:15:00",
    			"19:15:00 - 19:30:00",
    			"19:30:00 - 19:45:00",
    			"19:45:00 - 20:00:00",
    			"20:00:00 - 20:15:00",
    			"20:15:00 - 20:30:00",
    			"20:30:00 - 20:45:00",
    			"20:45:00 - 21:00:00",
    			"21:00:00 - 21:15:00",
    			"21:15:00 - 21:30:00",
    			"21:30:00 - 21:45:00",
    			"21:45:00 - 22:00:00",
    			"22:00:00 - 22:15:00",
    			"22:15:00 - 22:30:00",
    			"22:30:00 - 22:45:00",
    			"22:45:00 - 23:00:00",
    			"23:00:00 - 23:15:00",
    			"23:15:00 - 23:30:00",
    			"23:30:00 - 23:45:00",
    			"23:45:00 - 24:00:00"
    		);

    kyzi007, 03 Декабря 2011

    Комментарии (65)
  10. PHP / Говнокод #8713

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    protected $_never_allowed_regex = array(
    					"javascript\s*:"			=> '[removed]',
    					"expression\s*(\(|&\#40;)"	=> '[removed]', // CSS and IE
    					"vbscript\s*:"				=> '[removed]', // IE, surprise!
    					"Redirect\s+302"			=> '[removed]'
    	);

    Это не разу не ковнокод, но строкой с // IE, surprise! не поделится, не смог)

    ЗЫ. это CodeIgniter 2.0.3 класс Security, строка 52

    Zerstoren, 02 Декабря 2011

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