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

    В номинации:
    За время:
  2. Куча / Говнокод #15889

    +133

    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
    open System
     
    let inline un激辛カレー<'a> (f:obj) (tuple:obj) =
      match tuple with
      | :? ('a * 'a * 'a) as tuple -> 
        let a , b , c = tuple
        match f with
        | :? ('a -> 'a -> 'a -> 'a) as f -> f a b c
        | _ -> failwith "type did not matched! 3"
      | :? ('a * 'a) as tuple ->
        let a,b = tuple
        match f with
        | :? ('a -> 'a -> 'a) as f -> f a b
        | _ -> failwith "type did not matched! 2"
      | :? 'a as tuple ->
        let a = tuple
        match f with
        | :? ('a -> 'a) as f -> f a
        | _ -> failwith "type did not matched! 1"
      | _ -> failwith "type did not matched! tuple"
     
    printfn"%A"<| un激辛カレー<float> (fun x->x + 1.) 2.
    printfn"%A"<| un激辛カレー<int> (+) (10,10)
    printfn"%A"<| un激辛カレー<string> (fun (x:string) y z->x + y + z) ("How ","are ","you?")

    HaskellGovno, 03 Мая 2014

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

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if(fileCounter < 1000){
          subDir =  "SUBDIREC.001";
          //много кода
        }else if (fileCounter < 2000 && fileCounter > 999){
          subDir =  "SUBDIREC.002";
          //много кода, плюс еще 17 таких же веток
        }else if (fileCounter < 20000 && fileCounter > 18999){
          subDir =  "SUBDIREC.020";
          //много кода
        }

    dm-ua, 30 Апреля 2014

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

    +136

    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
    SqlConnection con = new SqlConnection(connectionString);
                string sql = "SELECT idea.Id, idea.Small_text, idea.Full_text, idea.Example_text, ";
                sql = sql + " ul.FullName as Avtor, ref.Name as Status, even.date_act, (select count (*) from events ev where ev.id_action=2 and ev.id_target=idea.Id and ev.type_target=1) as CountComm, (select count (*) from events ev where ev.id_action=57 and ev.id_target=idea.Id and ev.type_target=1) as Voit, (select max(ev.date_act) from events ev where ev.id_action in (1,2,4,5,7,8,9,10,58,60,61,62,63,64,65,66,67,68,69,70,71,72,74) and ev.id_target=idea.Id and ev.type_target=1) as Last_action";
                sql = sql + " FROM Idea idea, UserLists ul, Refbook ref, Events even ";
                sql = sql + " WHERE idea.Avtor=ul.Id and idea.Status_id = ref.Id and even.id_action=1 and even.type_target=1 and even.id_target=idea.id ";
                if (id >= 0)
                    sql = sql + "  and idea.Status_id=" + id;
                if (id_avtor >= 0)
                    sql = sql + "  and idea.Avtor=" + id_avtor;
                sql = sql + " ORDER BY Last_action desc";
    
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.CommandType = CommandType.Text;
                List<Idea> Ideas = new List<Idea>();
                using (con)
                {
                    con.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Idea idea = GetIdeaInfo(Int32.Parse(reader["Id"].ToString()));
                        Ideas.Add(idea);
                    }
                    reader.Close();
                    return Ideas;
                }

    Принял еще один проект. ASP.NET MVC4. Автор уехал в Новую Зеландию.

    Vince, 28 Апреля 2014

    Комментарии (5)
  5. JavaScript / Говнокод #15835

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function getCallback( variable ){
        return function () {
            if (!private["loginManager"].isLogin() )
                return ( private["loginManager"].callbackReauth() && false) || null ;
            return private[variable];
        }
    };

    когда лень ставить лишние фигурные скобки ( все внимание на средний return )

    Dart_Sergius, 24 Апреля 2014

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

    +91

    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
    while usedthrds<>cn do
              begin
               i:=i+1;
               if manual=0 then
                if i>ccpun then
                 break;
               if manual=1 then
                begin
                 gotoxy(1,stroka);read(cputime[i]);
                end
               else
                begin
                 gotoxy(1,stroka);write(cputime[i]);
                end;
               realsumcpu:=cputime[i]+ost;
               sumcpu:=cputime[i]+ost;
               found:=0;
               bin:=0;
               min:=1;max:=cn;
               search:
               while (min<=max) and (found=0) do
                begin
                 bin:=bin+1;
                 mid:=(min+max)div 2;
                 if sumcpu<sortedthrd[mid] then
                  max:=mid-1
                 else
                  if  sumcpu>sortedthrd[mid] then
                   min:=mid+1
                  else
                   if used[mid]=1 then
                    begin
                     if mid<>cn then
                      begin
                       l:=1;
                       while sortedthrd[mid+l]=sortedthrd[mid] do
                        begin
                         if used[mid+l]<>1 then
                          begin
                            mdldmas:=sortedthrd[mid+l];
                            mdldnum:=sortednum[mid+l];
                            ost:=realsumcpu-mdldmas;
                            used[mid+l]:=1;
                            found:=1;break;
                          end;
                        l:=l+1;
                        if mid+l>cn then break;
                      end;
                  end;
                if (mid<>1) and (found=0) then
                  begin
                    l:=1;
                    while sortedthrd[mid-l]=sortedthrd[mid] do
                      begin
                        if used[mid-l]<>1 then
                          begin
                            mdldmas:=sortedthrd[mid-l];
                            mdldnum:=sortednum[mid-l];
                            ost:=realsumcpu-mdldmas;
                            used[mid-l]:=1;
                            found:=1;break;
                          end;
                        l:=l+1;
                        if mid-l<1 then break;
                      end;
                  end;
                break;
              end
            else
              begin
                mdldmas:=sortedthrd[mid];
                mdldnum:=sortednum[mid];
                used[mid]:=1;
                ost:=realsumcpu-mdldmas;
                found:=1;
                break;
              end;
          end;
    
    if (found=0) and (sumcpu>0) then
      begin
        sumcpu:=sumcpu-1;bin:=0;min:=1;max:=cn;
        goto search;
      end;
    if found=0 then
        ost:=realsumcpu
    else
      begin
        gotoxy(6,stroka);write (realsumcpu);gotoxy (12,stroka);write (mdldmas);gotoxy(18,stroka);write(mdldnum);gotoxy(24,stroka);write(ost);gotoxy(30,stroka);write(bin);
        stroka:=stroka+1;
      end;
    if found=1 then
      begin
        realsumcpu:=ost;
        sumcpu:=ost;
        found:=0;bin:=0;min:=1;max:=cn;
        goto search;
      end;

    Как студенты пишут сортировку (полная версия https://gist.github.com/Karasiq/11184652)

    jkhne4pijgberg, 22 Апреля 2014

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

    +155

    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
    /**
    * Handles Registration Links.
    *
    * @package s2Member\Registrations
    * @since 3.5
    *
    * @attaches-to ``add_action("init");``
    *
    * @return null Or exits script execution after redirection.
    */
    public static function register ()
    {
    	do_action ("ws_plugin__s2member_before_register", get_defined_vars ());
    
    	if (!empty ($_GET["s2member_register"])) // If they're attempting to access the registration system.
    		{
    			while (@ob_end_clean ()); // Clean any existing output buffers.
    
    			$msg_503 = _x ('<strong>Your Link Expired:</strong><br />Please contact Support if you need assistance.', "s2member-front", "s2member");
    
    			if (is_array ($register = preg_split ("/\:\.\:\|\:\.\:/", c_ws_plugin__s2member_utils_encryption::decrypt (trim (stripslashes ((string)$_GET["s2member_register"]))))))
    				{
    					if (count ($register) === 6 && $register[0] === "subscr_gateway_subscr_id_custom_item_number_time" /* Does the checksum value match up here? */)
    						{
    							if (is_numeric ($register[5]) && $register[5] <= strtotime ("now") && $register[5] >= strtotime ("-" . apply_filters ("ws_plugin__s2member_register_link_exp_time", "2 days", get_defined_vars ())))
    								{
    									$_COOKIE["s2member_subscr_gateway"] = /* For ``reg_cookies_ok ()``. */ c_ws_plugin__s2member_utils_encryption::encrypt ($register[1]);
    									$_COOKIE["s2member_subscr_id"] = /* For ``reg_cookies_ok ()``. */ c_ws_plugin__s2member_utils_encryption::encrypt ($register[2]);
    									$_COOKIE["s2member_custom"] = /* For ``reg_cookies_ok ()``. */ c_ws_plugin__s2member_utils_encryption::encrypt ($register[3]);
    									$_COOKIE["s2member_item_number"] = /* For ``reg_cookies_ok ()``. */ c_ws_plugin__s2member_utils_encryption::encrypt ($register[4]);
    
    									if (($reg_cookies = c_ws_plugin__s2member_register_access::reg_cookies_ok ()) && extract ($reg_cookies) /* Needed? */)
    										{
    											status_header(200); // Send a 200 OK status header.
    											header("Content-Type: text/html; charset=UTF-8"); // Content-Type with UTF-8.
    
    											setcookie ("s2member_subscr_gateway", $_COOKIE["s2member_subscr_gateway"], time () + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie ("s2member_subscr_gateway", $_COOKIE["s2member_subscr_gateway"], time () + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN);
    											setcookie ("s2member_subscr_id", $_COOKIE["s2member_subscr_id"], time () + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie ("s2member_subscr_id", $_COOKIE["s2member_subscr_id"], time () + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN);
    											setcookie ("s2member_custom", $_COOKIE["s2member_custom"], time () + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie ("s2member_custom", $_COOKIE["s2member_custom"], time () + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN);
    											setcookie ("s2member_item_number", $_COOKIE["s2member_item_number"], time () + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie ("s2member_item_number", $_COOKIE["s2member_item_number"], time () + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN);
    
    											do_action ("ws_plugin__s2member_during_register", get_defined_vars ());
    
    											if (is_multisite () && c_ws_plugin__s2member_utils_conds::is_multisite_farm () && is_main_site () && ($location = c_ws_plugin__s2member_utils_urls::wp_signup_url ()))
    												{
    													echo '<script type="text/javascript">' . "\n";
    													echo "window.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq ($location) . "';";
    													echo '</script>' . "\n";
    												}
    											else if (($location = c_ws_plugin__s2member_utils_urls::wp_register_url ()))
    												{
    													echo '<script type="text/javascript">' . "\n";
    													echo "window.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq ($location) . "';";
    													echo '</script>' . "\n";
    												}
    											exit (); // Clean exit. The browser will now be redirected to ``$location``.
    										}
    									else
    										status_header(503) . header ("Content-Type: text/html; charset=UTF-8") . exit ($msg_503);
    								}
    							else
    								status_header(503) . header ("Content-Type: text/html; charset=UTF-8") . exit ($msg_503);
    						}
    					else
    						status_header(503) . header ("Content-Type: text/html; charset=UTF-8") . exit ($msg_503);
    				}
    			else
    				status_header(503) . header ("Content-Type: text/html; charset=UTF-8") . exit ($msg_503);
    		}
    
    	do_action ("ws_plugin__s2member_after_register", get_defined_vars ());
    }

    Концовка особенно захватывающа.

    Плагин для Wordpress - s2member, https://www.s2member.com/codex/stable/source/s2member/includes/classes/register-in.inc.php

    antongorodezkiy, 20 Апреля 2014

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

    +61

    1. 1
    std::cout << std::cout << "Hello, world";

    С гейдевчика, странно, что здесь не было.

    DlangGovno, 17 Апреля 2014

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

    +152

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    // Will we have a result object instantiated? If not - we'll simply return TRUE
    if ($return_object !== TRUE) {
    	if ($this->cache_on === TRUE && $this->cache_autodel === TRUE && $this->_cache_init()) {
    		$this->CACHE->delete();
    	}
    	return TRUE;
    }
    
    // Return TRUE if we don't need to create a result object
    if ($return_object !== TRUE) {
    	return TRUE;
    }

    Codeigniter / классика
    https://github.com/EllisLab/CodeIgniter/blob/develop/system/database/DB_driver.php#L668

    Fike, 09 Апреля 2014

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

    +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
    /**
         * Определение типа документа - Комплектация/Разукомплектация
         * @param $reverse
         * @return string
         */
        protected function get_reverse($reverse)
        {
            if(in_array($reverse, ['TRUE', 'true', true, 1, '1'], true)) {
                return 'TRUE';
            }
            if(in_array($reverse, ['FALSE', 'false', false, 0, '0', ''], true)) {
                return 'FALSE';
            }
        }

    Продолжение вот этого http://govnokod.ru/15643 кода придется делать

    smpl, 02 Апреля 2014

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

    +162

    1. 1
    $arOrders[$arDetail['PROPERTIES']['YC_ORDER']['VALUE']]['ORDER_DETAILS'][$arDetail['PROPERTIES']['YC_CITY']['VALUE']][] = $arDetail['ID'];

    Черный пояс по заполнению массивов

    TBoolean, 01 Апреля 2014

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