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

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

    +58

    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
    if(ext == ".wav")
    		{
    			if(main_header.bitsPerSample == 8)
    			{
    				switch(main_header.bitsPerSample)
    				{
    					case 8:
    					{
    						open_mode = n8bit_mode;
    					}break;
    					case 16:
    					{
    						open_mode = n16bit_mode;
    					}break;
    					default: open_mode = nNULL;
    				}
    ....далее какото код
    }

    ...

    GreatMASTERcpp, 25 Августа 2014

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

    +58

    1. 1
    #define CHK( x ) {do{if (x == MBRES_ERR){goto __gotoFAIL;}} while (FALSE);}

    Из SDK корейского сканера

    snw, 08 Августа 2014

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

    +58

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    Poor man' link time code generation:
    
    #include "main.cpp"
    #include "frame.cpp"
    #include "func.cpp"
    #include "account.cpp"
    #include "advancer.cpp"
    #include "audit.cpp"
    #include "cpio.cpp"
    
    g++ -whole-program -o my books.exe -O3 includeall.cpp

    http://blogs.msdn.com/b/oldnewthing/archive/2014/06/06/10531604.aspx

    someone, 07 Июня 2014

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

    +58

    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
    template <typename T>
    class MySharedPtr{
    public:
      explicit MySharedPtr(T* obj) : _obj(obj){}
      // --> я дописал
      MySharedPtr(const MySharedPtr& other) : _obj(other._obj){ inc_ref_count(_obj);}
      // <-- я дописал
      MySharedPtr& operator=(const MySharedPtr& other) {
        // --> я дописал
        if (this == &other)
          return *this;
        // <-- я дописал
        _obj = other._obj;
        inc_ref_count(_obj);
      }
      ~MySharedPtr(){
        dec_ref_count(_obj);
      }
    
    private:
      static void inc_ref_count(T* obj){
        std::lock_guard<std::mutex> lock(_mutex);
        _ref_count[obj] ++ ;
      }
    
      static void dec_ref_count(T* obj){
        std::lock_guard<std::mutex> lock(_mutex);
        if (--_ref_count[obj]){
          delete obj;
          _ref_count.erase(_ref_count.find(obj));
        }
      }
    
      T* _obj;
    
      static std::mutex MySharedPtr<T>::_mutex;
      static std::map<T*,int> MySharedPtr<T>::_ref_count;
    };
    
    
    template <typename T>
    std::map<T*,int> MySharedPtr<T>::_ref_count;
    
    
    template <typename T>
    std::mutex MySharedPtr<T>::_mutex;

    сегодня приходил чел-выпускник, написал на листочке shared_ptr, какое ваше мнение?

    LispGovno, 14 Февраля 2014

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

    +58

    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
    private void getPCTurn(char s){
            int done = 0;
            System.out.println("Now the turn of " + s +" \n Computer thinking...");
            analysis:
                while(done == 0){
                    int numbX;
                    for(int i = 0; i < field.length; i++){
                         numbX = 0; // check horisontals for 00
                        for (int j = 0; j < field.length; j++){
                            if (field[i][j] == s){
                                numbX++;
                            }
                            if (numbX == (field.length-1)){
                                for (j = 0; j < field.length; j++){
                                    if (field[i][j] == DEF_FIELD){
                                        field[i][j] = s;
                                        done++;
                                        break analysis;
                                    }
                                }
                            }
                        }
                        numbX = 0; // check verticals for 00
                        for (int j = 0; j < field.length; j++){
                            if (field[j][i] == s){
                                numbX++;
                            }
                            if (numbX == (field.length-1)){
                                for (j = 0; j < field.length; j++){
                                    if (field[j][i] == DEF_FIELD){
                                        field[j][i] = s;
                                        done++;
                                        break analysis;
                                    }
                                }
                            }
                        }
                    }
                     numbX = 0; //check diagonal for 00
                        for (int i = 0;i < field.length; i++){
                            if (field[i][i] == s){
                                numbX++;
                            }
                            if (numbX == (field.length-1)){
                                for (i = 0;i < field.length; i++){
                                    if (field[i][i] == DEF_FIELD){
                                        field[i][i] = s;
                                        done++;
                                        break analysis;
                                    }
                                }
                            }
                        }
                        numbX = 0; // check second diagonal for 00
                        for (int i = (field.length - 1);i >= 0; i--){
                            int j = (field.length - 1)-i;
                            if (field[i][j] == s){
                                numbX++;
                            }
                            if (numbX == (field.length-1)){
                                for (i = (field.length - 1);i >= 0; i--){
                                    j = (field.length - 1)-i;
                                    if (field[i][j] == DEF_FIELD){
                                        field[i][j] = s;
                                        done++;
                                        break analysis;
                                    }
                                }
                            }
                        }
                    for(int i = 0; i < field.length; i++){
                        numbX = 0; // check horisontals for XX
                        for (int j = 0; j < field.length; j++){
                            if (field[i][j] != s && field[i][j] != DEF_FIELD){
                                numbX++;
                            }
                            if (numbX == (field.length-1)){
                                for (j = 0; j < field.length; j++){
                                    if (field[i][j] == DEF_FIELD){
                                        field[i][j] = s;
                                        done++;
                                        break analysis;
                                    }
                                }
                            }
                        }
    
    // to be continued ...

    "Незамысловатая" реализация искусственного интеллекта для игры "Крестики-Нолики" от sv1979.
    Оригинал -> https://github.com/sv1979/svhome1/blob/master/src/TicTacToe/Field.java

    W1nneR, 31 Июля 2013

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

    +58

    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
    private function  _getOrderBy($orderField)
        {
            switch ($orderField)
            {
                case 'ProductID':
                    return 'ProductID';
                case 'ProductName':
                    return 'ProductName';
                case 'Per':
                    return 'Per';
                case 'Start':
                    return 'Start';
                case 'Qty':
                    return 'Qty';
                case 'OrderDetailsID':
                    return 'OrderDetailsID';
                case 'FIOUr':
                    return 'FIOUr';
                case 'AddressUr':
                    return 'AddressUr';
                case 'ZipCodeUr':
                    return 'ZipCodeUr';
                case 'OrderRealSupID':
                    return 'OrderRealSupID';
                case 'PayDate':
                    return 'PayDate';
                case 'SumPay':
                    return 'SumPay';
                case 'NumPlPor':
                    return 'NumPlPor';
                default:
                    return 'OrderID';
            }
        }
    
    //Вот еще чуть-чуть:
    
    private function  _getOrderType($orderType)
        {
            switch ($orderType)
            {
                case 'asc':
                    return 'asc';
                default:
                    return 'desc';
            }
        }

    Ну в общем, привожу пару этюдов из "коричневой" симфонии, которые используются для формирования SQL запроса. Код - прост, но говнист.

    SunnyMagadan, 17 Декабря 2012

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

    +58

    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
    // Released Under Affero General Public License, Version 3 (AGPL3)
    // Author: [email protected]
    
    $result = "TRUE";
    
    $testable_string = strtolower($string_to_test);
    $testable_string_length = strlen($string_to_test);
    
    for($i_string = 0; $i_string < $testable_string_length; $i_string++)
    {
        $current_value_to_test = $testable_string[$i_string];
       
        if(    ($current_value_to_test != "0")        &&
            ($current_value_to_test != "1")        &&
            ($current_value_to_test != "2")        &&
            ($current_value_to_test != "3")        &&
            ($current_value_to_test != "4")        &&
            ($current_value_to_test != "5")        &&
            ($current_value_to_test != "6")        &&
            ($current_value_to_test != "7")        &&
            ($current_value_to_test != "8")        &&
            ($current_value_to_test != "9")        &&
            ($current_value_to_test != "a")        &&
            ($current_value_to_test != "b")        &&
            ($current_value_to_test != "c")        &&
            ($current_value_to_test != "d")        &&
            ($current_value_to_test != "e")        &&
            ($current_value_to_test != "f")        )
        {
            $result = "FALSE";
            $i_string = $testable_string_length;
        }
    }

    Смахивает на баян, но тем не менее.
    http://php.net/manual/ru/function.is-numeric.php, из комментов.

    RaZeR, 14 Декабря 2012

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

    +58

    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
    $coder=0; // 1-cp1251(Win)/0-UTF
    
    
    function mont ($date)
    {
    global $coder;
    if ($coder){
    $date=str_replace('January', 'ßíâàðÿ', $date);
    $date=str_replace('February', 'Ôåâðàëÿ', $date);
    $date=str_replace('March', 'Ìàðòà', $date);
    $date=str_replace('April', 'Àïðåëÿ', $date);
    $date=str_replace('May', 'Ìàÿ', $date);
    $date=str_replace('June', 'Èþíÿ', $date);
    $date=str_replace('July', 'Èþëÿ', $date);
    $date=str_replace('August', 'Àâãóñòà', $date);
    $date=str_replace('September', 'Ñåíòÿáðÿ', $date);
    $date=str_replace('October', 'Îêòÿáðÿ', $date);
    $date=str_replace('November', 'Íîÿáðÿ', $date);
    $date=str_replace('December', 'Äåêàáðÿ', $date);
    }
    else
    {
    $date=str_replace('January', 'Января', $date);
    $date=str_replace('February', 'Февраля', $date);
    $date=str_replace('March', 'Марта', $date);
    $date=str_replace('April', 'Апреля', $date);
    $date=str_replace('May', 'Мая', $date);
    $date=str_replace('June', 'Июня', $date);
    $date=str_replace('July', 'Июля', $date);
    $date=str_replace('August', 'Августа', $date);
    $date=str_replace('September', 'Сентября', $date);
    $date=str_replace('October', 'Октября', $date);
    $date=str_replace('November', 'Ноября', $date);
    $date=str_replace('December', 'Декабря', $date);
    }
    return $date;
    }

    в каком-то исходнике комментариев...

    deep, 24 Сентября 2012

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

    +58

    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
    // что-то страшно мне стало
    class Mysql{
      private $db = null; 
      private $result = null; 
    //private $row = null;
     
     function __construct($dbname,$dbuser,$dbpass,$dbhost){
        $this->db = mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
        mysql_select_db($dbname) or die ("<br>Invalid query: " . mysql_error());
        mysql_query("SET NAMES utf8") or die ("<br>Invalid query: " . mysql_error());
     }
     function connect(){
        if(!$this->db){
        exit("Error connect BD!");
        }
     }
    
     function query($query){
        if(!$query){exit("No [query]");}
    	$this->result = $query = mysql_query($query) or die ("<br>Invalid query: " . mysql_error());
    	return $query;
     } 
    }

    kuler, 13 Сентября 2012

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

    +58

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function abs_url_text ($text, $base_url) {
       define(BASE_URL, $base_url); 
    ...
    ... BASE_URL . "\"";
    
    }

    Реально серьёзный подход.
    Садо-мазо!

    virtual_cia, 11 Сентября 2012

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