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

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

    +73

    1. 1
    progress = progress != null ? progress + "%" : progress;

    Да, давно я не смеялся...

    raorn, 11 Августа 2010

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

    +111

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public static byte[] Length_Hex(long _Length)
            {
                byte[] Buf = { (byte)(_Length >> 0), (byte)(_Length >> 8), (byte)(_Length >> 16), (byte)(_Length >> 24) };
                return Buf;
            }

    Кривой велик

    Nigma143, 06 Августа 2010

    Комментарии (19)
  4. JavaScript / Говнокод #3777

    +165

    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
    // Color and text
    // -- Безупречный
    if (nScore >= 90)
    {
    var strText = "Отличный пароль! Главное не забыть его :) ";
    var strColor = "#0ca908";
    }
    // -- Очень хороший
    else if (nScore >= 80)
    {
    var strText = "Очень хороший";
    vstrColor = "#7ff67c";
    }
    // -- Хороший
    else if (nScore >= 70)
    {
    var strText = "Хороший";
    var strColor = "#1740ef";
    }
    // -- Давольно нормальный
    else if (nScore >= 60)
    {
    var strText = "Достаточно неплохо";
    var strColor = "#5a74e3";
    }
    // -- Нормальный
    else if (nScore >= 50)
    {
    var strText = "Нормально";
    var strColor = "#e3cb00";
    }
    // -- Слабый
    else if (nScore >= 25)
    {
    var strText = "Слабенько";
    var strColor = "#e7d61a";
    }
    // -- Очень плохой
    else
    {
    var strText = "Ужас. (qwerty и то лучше :) ) ";
    var strColor = "#e71a1a";
    }

    else if (nScore >= 25)
    {
    var strText = "Слабенько";
    var strColor = "#e7d61a"; // -- Слабенько?WTF???????
    }

    Взято с блога великого кодера darkoff.ru

    BlincAttack, 25 Июля 2010

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

    +166

    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
    switch(count($Args)) {
             case 0:
                $Result = new $ClassName; break;
             case 1:
                $Result = new $ClassName($Args[0]); break;
             case 2:
                $Result = new $ClassName($Args[0], $Args[1]); break;
             case 3:
                $Result = new $ClassName($Args[0], $Args[1], $Args[2]); break;
             case 4:
                $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3]); break;
             case 5:
                $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4]); break;
             case 6:
                $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5]); break;
             case 7:
                $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6]); break;
             case 8:
                $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], $Args[7]); break;
             default:
                throw new Exception();
          }

    Взято из форума Vanilla 2...

    И еще в одном файле подобное library/core/class.dispatcher.php (со строки 267).

    Александр Михалицын, 24 Июля 2010

    Комментарии (19)
  6. Си / Говнокод #3766

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    inline Gdiplus::Color colorrefToGdiColor(COLORREF col, char alpha)
    {
    	return (static_cast<unsigned long>(static_cast<unsigned char>((col & Gdiplus::Color::RedMask) >> Gdiplus::Color::RedShift)) <<   Gdiplus::Color::BlueShift) | (static_cast<unsigned long>(static_cast<unsigned char>((col & Gdiplus::Color::GreenMask) >> Gdiplus::Color::GreenShift)) << Gdiplus::Color::GreenShift) | (static_cast<unsigned long>(static_cast<unsigned char>((col & Gdiplus::Color::BlueMask) >> Gdiplus::Color::BlueShift)) << Gdiplus::Color::RedShift) | (static_cast<unsigned long>(alpha) << Gdiplus::Color::AlphaShift);
    }

    Тихо себя ненавижу. Слава Б-г'у это всё выкидывается.

    Altravert, 23 Июля 2010

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

    +176

    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
    function NDS($poisk)
    {
    	preg_match('#БЕЗ НДС#', $poisk, $matches);
    	if(empty($matches[0]))
    	{
    		preg_match('#без НДС#', $poisk, $matches);
    	   	if(empty($matches[0]))
    		{
    			preg_match('#НДС НЕТ#', $poisk, $matches);
    		 	if(empty($matches[0]))
    			{
    			  	 preg_match('#НДС нет#', $poisk, $matches);
    		 		 if(empty($matches[0]))
    				 {
    			  		preg_match('#НДС не облагается#', $poisk, $matches);
    				 	if(empty($matches[0]))
    					{
    					   	preg_match('#НДС НЕ ОБЛАГАЕТСЯ#', $poisk, $matches);
    					 	if(empty($matches[0]))
    					 	{
    					 		preg_match('#НДС НЕ ПРЕДУСМОТРЕН#', $poisk, $matches);
    					 		if(empty($matches[0]))
    					 		{
    							   preg_match('#Без налога (НДС)#', $poisk, $matches);
    					 		   if(empty($matches[0]))
    					 		   {
    									preg_match('#НДС: БЕЗ НАЛОГА#', $poisk, $matches);
    					 				if(empty($matches[0]))
    					 				{
    					 				   preg_match('#Без НДС#', $poisk, $matches);
    					 				   if(empty($matches[0]))
    					 				   {
    					 				   	  preg_match('#без налога (НДС)#', $poisk, $matches);
    					 					  if(empty($matches[0]))
    					 					  {}
    					 					  else  return true;
    					 				   }
    					 				   else  return true;
    					 				}
    					 				else  return true;
    					 		   }
    					 		   else  return true;
    					 		}
    					 		else  return true;
    					 	}
    						else  return true;
    					}
    					else return true;
    				  }
    				  else return true;
    			}
    			else return true;
    		}
    		else return true;
    	}
    	else return true;
    }

    Обнаружено в старом проекте заказчика

    UncleRus, 16 Июля 2010

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    m_lActiveTab = GetCurSel();
    for (int i = 0; i < GetItemCount(); i++)
    	m_cItemSelected[m_lActiveTab] = false;
    m_cItemSelected[m_lActiveTab] = true;

    Вот так говнокодят в крупных проектах

    Snake2101, 14 Июля 2010

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

    +174

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function disconnect_db($link) {
    	mysql_close($link);
    	unset($link);
    	$link = null;
    }

    а ты уверен, что ты отключился от ДБ?

    qbbr, 08 Июля 2010

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

    +144

    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
    07.07.2010 14:49:14 com.mchange.v2.c3p0.C3P0Registry banner
    INFO: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace:
     10]
    07.07.2010 14:49:15 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoo
    lManager
    INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acqu
    ireIncrement -> 5, acquireRetryAttempts -> 0, acquireRetryDelay -> 500, autoComm
    itOnClose -> true, automaticTestTable -> connection_test_table, breakAfterAcquir
    eFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null,
    connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, d
    ataSourceName -> mo0lz2891bvagwh7rwflk|11e1e67, debugUnreturnedConnectionStackTr
    aces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factor
    yClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToke
    n -> mo0lz2891bvagwh7rwflk|11e1e67, idleConnectionTestPeriod -> 3600, initialPoo
    lSize -> 10, jdbcUrl -> jdbc:mysql://localhost/mysql, maxAdministrativeTaskTime
    -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0
    , maxPoolSize -> 10, maxStatements -> 0, maxStatementsPerConnection -> 100, minP
    oolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0
    , preferredTestQuery -> null, properties -> {user=******, password=******}, prop
    ertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> fa
    lse, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false
     ]
    07.07.2010 14:49:15 com.l2scoria.loginserver.LoginController <init>
    INFO: Loading LoginContoller...
    07.07.2010 14:49:21 com.l2scoria.loginserver.LoginController <init>
    INFO: Cached 10 KeyPairs for RSA communication
    Exception in thread "main" java.lang.NullPointerException
            at com.l2scoria.util.random.MTRandom.next(MTRandom.java:355)
            at java.util.Random.nextDouble(Random.java:438)
            at com.l2scoria.util.random.Rnd.nextInt(Rnd.java:55)
            at com.l2scoria.loginserver.LoginController.generateBlowFishKeys(LoginCo
    ntroller.java:176)
            at com.l2scoria.loginserver.LoginController.<init>(LoginController.java:
    138)
            at com.l2scoria.loginserver.LoginController.load(LoginController.java:10
    3)
            at com.l2scoria.loginserver.L2LoginServer.<init>(L2LoginServer.java:117)
    
            at com.l2scoria.loginserver.L2LoginServer.main(L2LoginServer.java:61)
    
    LoginServer terminated abnormaly
    Send you bug to : http://la2.100nt.ru
    
    
    LoginServer terminated
    Send you bug to : http://la2.100nt.ru
    
    Restart(r) or Quit(q)^CTerminate batch job (Y/N)?

    leonius, 07 Июля 2010

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

    +158

    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
    <?php  
    // Подключаемься к базе данных  
    require_once ("bd.php");  
     $query = 'SELECT MAX(id) AS `id` FROM `data`';  
            $result = mysql_query($query) or die("Query failed : " . mysql_error());  
    /* Выводим результаты в html */ 
            $line = mysql_fetch_array($result, MYSQL_ASSOC);  
    //================Настройки============= //  
    $fotos_dir = "fotos/"; // Директория для фотографий 
    $foto_name = $fotos_dir.time()."_".basename($_FILES['myfile']['name']); // Полное имя файла вместе с путем  
    $foto_light_name = $line['id']+1; 
    $foto_light_name2 = $foto_light_name.".".basename($_FILES['myfile']['type']); 
    //$foto_light_name = time()."_".basename($_FILES['myfile']['name']); // Имя файла исключая путь  
    // Текст ошибок  
    $error_by_mysql = "<span style=\"font: bold 15px tahoma; color: red;\">Ошибка при добавлении данных в базу</span>";  
    $error_by_file = "<span style=\"font: bold 15px tahoma; color: red;\">Невозможно загрузить файл в директорию. Возможно её не существует</span>";  
    // Начало  
    if(isset($_FILES["myfile"]))  
    {  
    $myfile = $_FILES["myfile"]["tmp_name"];  
    $myfile_name = $_FILES["myfile"]["name"];  
    $myfile_size = $_FILES["myfile"]["size"];  
    $myfile_type = $_FILES["myfile"]["type"];  
    $error_flag = $_FILES["myfile"]["error"];  
    // Если ошибок не было  
    if($error_flag == 0)  
    {  
    $DOCUMENT_ROOT = $_SERVER['DOCMENT_ROOT'];  
    $upfile = getcwd()."\\fotos\\" ."site.ru_".$foto_light_name2;  
    if ($_FILES['myfile']['tmp_name'])  
    {  
    //Если не удалось загрузить файл  
    if (!move_uploaded_file($_FILES['myfile']['tmp_name'], $upfile))   
    {  
    echo "$error_by_file";  
    exit;  
    }  
    }  
    else  
    {  
        echo 'Проблема: возможна атака через загрузку файла. ';  
        echo $_FILES['myfile']['name'];  
        exit;  
    }  
    // После удачной обработки файла, выводим сообщение  
    echo "<h3>Результат добавления обоины:</h3> <br />";  
    echo "Файл <b>".$foto_light_name2."</b> успешно добавлен<br />";  
    // Заносим путь картинки в базу данных  
    $q = "INSERT INTO data (foto,dir) VALUES ('$foto_light_name2','$fotos_dir')";  
    $query = mysql_query($q);  
    // Данные успешно внесены в базу данных, выводим сообщение  
    if ($query == 'true') {  
    echo "<br /><b>Данные успешно внесены в базу</b>";  
    }  
    // В противном случае, выводим ошибку при добавлении в базу данных  
    else {  
    echo "$error_by_mysql";  
    }  
            }  
       
     elseif ($myfile_size == 0) {  
     echo "Пустая форма!";  
     }     
    } 
    ?>

    оригинал http://forum.searchengines.ru/showpost.php?p=7226101&postcount=1 не шедевр, но говнокод присутствует.
    $DOCUMENT_ROOT = $_SERVER['DOCMENT_ROOT']; - это так логично ...

    GoodTalkBot, 07 Июля 2010

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