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

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

    +168

    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
    function test_file_for_smells( $filename )
       {
       global $MAX_FUNCTION_LINE_COUNT, $MAX_INDENTATION_LEVEL;
       $function_line_count = 0;
       $found_continued_line = 0;
       $line_number = 0;
       $fp = fopen( $filename, "r" );
       if( ! $fp )
         return;
       while( ! feof( $fp ) )
         {
         $line = chop( fgets( $fp, 4096 ) );
         $line_number++;
         while( substr( $line, 0, 9 ) == "function "  &&
                substr( $line, strlen($line) - 1, 1 ) != ')' )
           {
           $line = $line . chop( fgets( $fp, 4096 ) )
           $found_continued_line++;
           }
         if( substr( $line, 0, 9 ) == "function " )
           {
           $function_line_count = 1;
           $function_name = substr( $line, 9, strpos($line, '(') - 9 );
           }
         if( $function_line_count > 0 )
           {
           if( $line == "\t}" )
             {
             $function_line_count = $function_line_count - 3;
             if( $function_line_count > $MAX_FUNCTION_LINE_COUNT )
               print_warning( $filename, $line, $line_number, "$function_name() too long ($function_line_count lines)" );
             $function_line_count = 0;
             }
           else
             $function_line_count++;
           $result = test_line_for_indentation( $line, $MAX_INDENTATION_LEVEL );
           if( ! $result )
             print_warning( $filename, $line, $line_number, "Too much nesting." );
           $result = test_line_for_function_definition( $line, $MAX_NUM_PARAMETERS );
           if( ! $result )
             print_warning( $filename, $line, $line_number, "Too many parameters." );
           if( $found_continued_line > 0 )
             {
             $line_number += $found_continued_line;
             $found_continued_line = 0;
             }
           }
         }
       }

    Детектор говнокода!!!!

    fork, 10 Декабря 2010

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

    +145

    1. 1
    2. 2
    3. 3
    <?php
    
    die 'Превьюшки пока что не обрабатываются.';

    Либо я уже спятил и что-то делаю не так, либо php.
    die ('Превьюшки пока что не обрабатываются.'); работает на ура, а данный пример выбивает мне Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING.
    Ничего не понимаю.

    7ion, 04 Декабря 2010

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

    +126

    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
    private int VedOrderBy(int N_VED)
        {
            switch (N_VED)
            {
                case 2:
                    return 3;
                    break;
                case 3:
                    return 5;
                    break;
                case 4:
                    return 1;
                    break;
                case 5:
                    return 0;
                    break;
                case 6:
                    return 4;
                    break;
                case 7:
                    return 6;
                    break;
                case 8:
                    return 2;
                    break;
            }
            return 10;
        }

    foondook, 25 Ноября 2010

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

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    function eval()
    {
        this.obj = eval(obj);
    }

    выкопал из сорцов игрушки...

    Lure Of Chaos, 24 Ноября 2010

    Комментарии (10)
  6. C# / Говнокод #4699

    +118

    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
    if(wordApp != null)
                    {
                        try
                        {
                            if(isNewApp && wordApp.Documents.Count == 0)
                            {
                                object arg1 = Word.WdSaveOptions.
                                                wdDoNotSaveChanges;
                                object arg2 = null;
                                object arg3 = null;
                                wordApp.Quit(ref arg1, ref arg2, ref arg3);
    
                                // Wait until Word shuts down.
    
                                for(;;)
                                {
                                    Thread.Sleep(100);
                                    try
                                    {
                                        // When word shuts down this call 
    
                                        // throws an exception.
    
                                        string dummy = wordApp.Version;
                                    }
                                    catch
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        catch {}
    
                        wordApp = null;
                    }

    Вот такой вот Dispose для ворда
    http://www.codeproject.com/KB/cs/winwordloader.aspx

    Lennis, 21 Ноября 2010

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

    +162

    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
    // the next few lines do the fiddling required to make sure the data 
    // looks right, whether it's viewed via the RSS feed or via the database
    $longpost=str_replace("<br />", "\n", $post);
    $shortpost=substr($post,0,600);
    $shortpost=str_replace("<br />", "\n", $shortpost);
    $pass=$_POST["pass"];
    if ($pass == $password) {
    	include "db.inc";
    	// this line actually inserts the data
    	mysql_query("INSERT INTO entries VALUES (NULL, '$title', '$post')");
    	$getid=mysql_query("SELECT id FROM entries WHERE title='$title'");
    	$myrow=mysql_fetch_array($getid);
    	$postid=$myrow["id"];
    	// from here on in, we're building the RSS feed.
    	$arrFp = file("rss/feed.xml");
    	$lines = count($arrFp);
    	$insertat = $lines-2;
    	for ($i=0; $i<$insertat; $i++) {
    		$rsstext=$rsstext.$arrFp[$i];
    	}
    	$rsstext=$rsstext."<item>\n";
    	$rsstext=$rsstext."<title>".stripslashes($title)."</title>\n";
    	$rsstext=$rsstext."<description>".stripslashes($shortpost);
    	if (strlen($shortpost)<strlen($longpost)) {
    		$rsstext=$rsstext."...";
    	}
    	$rsstext=$rsstext."</description>\n";
    	$rsstext=$rsstext."<link>$url/comment.php?post=$postid</link>\n";
    	$rsstext=$rsstext."</item>\n";
    	$rsstext=$rsstext."</channel>\n";
    	$rsstext=$rsstext."</rss>";
    	$fp=fopen("rss/feed.xml", "w");
    	fwrite( $fp, $rsstext );
    	fclose($fp);
    	echo "Post successfully submitted!";
    } else {
    	echo "You are not authorised to post to this server!";
    }

    Создаём RSS-ленту.

    Yurik, 20 Ноября 2010

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

    +121

    1. 1
    2. 2
    3. 3
    4. 4
    if (Convert.ToBoolean(ViewState["IsProgram"]) != null && Convert.ToBoolean(ViewState["IsProgram"]))
    {
        // do work
    }

    Это взорвало мой мозг...

    rstrg, 13 Ноября 2010

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

    +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
    <?php
    # bla bla bla...
    public function __construct ($dbname, $host = null, $user = null, $pass = null) {
    
    	$numargs = func_num_args ();
    	if ($numargs == 1)
    		parent::__construct ($dbname);
    	else
    		parent::__construct ($dbname, $host = null, $user = null, $pass = null);
            $this->begin = time ();
      }
    # bla bla bla...

    "гениальный" вызов конструктора!

    dwinner, 12 Ноября 2010

    Комментарии (10)
  10. C# / Говнокод #4590

    +130

    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
    if ((!(((constmonth == 1) && (Finalday > 31))
    || ((constmonth == 2) && (Finalyear % 4 == 0) && (Finalday > 29))
    || ((constmonth == 2) && (Finalyear % 4 != 0) && (Finalday> 28))
    || ((constmonth == 3) && (Finalday > 31))
    || ((constmonth == 4) && (Finalday > 30))
    || ((constmonth == 5) && (Finalday > 31))
    || ((constmonth == 6) && (Finalday > 30))
    || ((constmonth == 7) && (Finalday > 31))
    || ((constmonth == 8) && (Finalday > 31))
    || ((constmonth == 9) && (Finalday > 30))
    || ((constmonth == 10) && (Finalday > 31))
    || ((constmonth == 11) && (Finalday > 30))
    || ((constmonth == 12) && (Finalday > 31))))
    && ((((constmonth + 1 == 1) && (Finalday > 31))
    || ((constmonth + 1 == 2) && (Finalyear % 4 == 0) && (Finalday > 29))
    || ((constmonth + 1 == 2) && (Finalyear % 4 != 0) && (Finalday > 28))
    || ((constmonth + 1 == 3) && (Finalday > 31))
    || ((constmonth + 1 == 4) && (Finalday > 30))
    || ((constmonth + 1 == 5) && (Finalday > 31))
    || ((constmonth + 1 == 6) && (Finalday > 30))
    || ((constmonth + 1 == 7) && (Finalday > 31))
    || ((constmonth + 1 == 8) && (Finalday > 31))
    || ((constmonth + 1 == 9) && (Finalday > 30))
    || ((constmonth + 1 == 10) && (Finalday > 31))
    || ((constmonth + 1 == 11) && (Finalday > 30))
    || ((constmonth + 1 == 12) && (Finalday > 31)))))
    {
    if ((constmonth + 1 == 2) && (Finalyear % 4 == 0)) { Finalday = 29; }
    if ((constmonth + 1 == 2) && (Finalyear % 4 != 0)) { Finalday = 28; }
    
    switch (constmonth + 1)
    {
    case 1: Finalday = 31; break;
    case 3: Finalday = 31; break;
    case 4: Finalday = 30; break;
    case 5: Finalday = 31; break;
    case 6: Finalday = 30; break;
    case 7: Finalday = 31; break;
    case 8: Finalday = 31; break;
    case 9: Finalday = 30; break;
    case 10: Finalday = 31; break;
    case 11: Finalday = 30; break;
    case 12: Finalday = 31; break;
    }
    //constmonth++;

    GreBer, 11 Ноября 2010

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

    +146

    1. 1
    $news = new news($_GET["news"]);

    Обьект класса news. Выводит нужную новость в соответствии с get запросом.

    Somov, 09 Ноября 2010

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