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

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    <?
    // ...
    preg_match('/^[0-9]{1,}$/', $value)     // positive integer
                            || (        // or negative integer
                                (substr($value, 0, 1) === '-')
                                && preg_match('/^[0-9]{1,}$/', substr($value, 1))
                            )
    
    ?>

    В битриксе так и не выучили регулярки..

    belukov, 12 Марта 2015

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

    −115

    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
    def _make_parser_function(name, sep=','):
    
        def parser_f(filepath_or_buffer,
                     sep=sep,
                     dialect=None,
                     compression=None,
    
                     doublequote=True,
                     escapechar=None,
                     quotechar='"',
                     quoting=csv.QUOTE_MINIMAL,
                     skipinitialspace=False,
                     lineterminator=None,
    
                     header='infer',
                     index_col=None,
                     names=None,
                     prefix=None,
                     skiprows=None,
                     skipfooter=None,
                     skip_footer=0,
                     na_values=None,
                     na_fvalues=None,
                     true_values=None,
                     false_values=None,
                     delimiter=None,
                     converters=None,
                     dtype=None,
                     usecols=None,
    
                     engine='c',
                     delim_whitespace=False,
                     as_recarray=False,
                     na_filter=True,
                     compact_ints=False,
                     use_unsigned=False,
                     low_memory=_c_parser_defaults['low_memory'],
                     buffer_lines=None,
                     warn_bad_lines=True,
                     error_bad_lines=True,
    
                     keep_default_na=True,
                     thousands=None,
                     comment=None,
                     decimal=b'.',
    
                     parse_dates=False,
                     keep_date_col=False,
                     dayfirst=False,
                     date_parser=None,
    
                     memory_map=False,
                     nrows=None,
                     iterator=False,
                     chunksize=None,
    
                     verbose=False,
                     encoding=None,
                     squeeze=False,
                     mangle_dupe_cols=True,
                     tupleize_cols=True,
                     ):
    
            # Alias sep -> delimiter.
            if delimiter is None:
                delimiter = sep
    
            kwds = dict(delimiter=delimiter,
                        engine=engine,
                        dialect=dialect,
                        compression=compression,
    
                        doublequote=doublequote,
                        escapechar=escapechar,
                        quotechar=quotechar,
                        quoting=quoting,
                        skipinitialspace=skipinitialspace,
                        lineterminator=lineterminator,
    
                        header=header,
                        index_col=index_col,
                        names=names,
                        prefix=prefix,
                        skiprows=skiprows,
                        na_values=na_values,
                        na_fvalues=na_fvalues,
                        true_values=true_values,
                        false_values=false_values,
                        keep_default_na=keep_default_na,
                        thousands=thousands,
                        comment=comment,
                        decimal=decimal,
    
                        parse_dates=parse_dates,
                        keep_date_col=keep_date_col,
                        dayfirst=dayfirst,
                        date_parser=date_parser,
    
                        nrows=nrows,
                        iterator=iterator, ....

    На самом деле оно в общем не такое уж и страшное потому что в питоне можно по имени аргументы в метод, но флешер в мне нервно икнул

    kyzi007, 10 Марта 2015

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

    +80

    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
    public Object convert(Object entity) {
            
            Object result = null;
            
            //TUser to UserDTO
            if(entity.getClass().isInstance(TUser.class)) {
                result = new UserDTO();
                ((UserDTO)result).setId(((TUser)entity).getId());
                ((UserDTO)result).setLogin(((TUser)entity).getLogin());
                ((UserDTO)result).setPassword(((TUser)entity).getPassword());
            } 
            
            //TState to StateDTO
            if(entity.getClass().isInstance(TState.class)) {
                result = new StateDTO();
                ((StateDTO)result).setId(((TState)entity).getId());
                ((StateDTO)result).setAlias(((TState)entity).getAlias());
                ((StateDTO)result).setCaption(((TState)entity).getCaption());
            } 
            
            //TSale to SaleDTO
            if(entity.getClass().isInstance(TSale.class)) {
                result = new SaleDTO();
                ((SaleDTO)result).setId(((TSale)entity).getId());
                ((SaleDTO)result).setBuyerInfo(((TSale)entity).getBuyerInfo());
                ((SaleDTO)result).setCreateDate(((TSale)entity).getCreateDate());
                ((SaleDTO)result).setNumber(((TSale)entity).getNumber());
                TState state = ((TSale)entity).getStateId();
                ((SaleDTO)result).setState((StateDTO)convert(state));
                TGoods goods = ((TSale)entity).getGoodsId();
                ((SaleDTO)result).setGoods((GoodsDTO)convert(goods));
            } 
            
            //TImage to ImageDTO
            if(entity.getClass().isInstance(TImage.class)) {
                result = new ImageDTO();
                ((ImageDTO)result).setId(((TImage)entity).getId());
                ((ImageDTO)result).setPath(((TImage)entity).getPath());
                TGoods goods = ((TImage)entity).getGoodsId();
                ((ImageDTO)result).setGoods((GoodsDTO)convert(goods));
            } 
            
            //TGoods to GoodsDTO
            if(entity.getClass().isInstance(TGoods.class)) {
                result = new GoodsDTO();
                ((GoodsDTO)result).setId(((TGoods)entity).getId());
                ((GoodsDTO)result).setName(((TGoods)entity).getName());
                ((GoodsDTO)result).setPrice(((TGoods)entity).getPrice());
                ((GoodsDTO)result).setDescription(((TGoods)entity).getDescription());
                TCategory category = ((TGoods)entity).getCategoryId();
                ((GoodsDTO)result).setCategory((CategoryDTO)convert(category));
            } 
            
            //TCategory to CategoryDTO
            if(entity.getClass().isInstance(TCategory.class)) {
                result = new CategoryDTO();
                ((CategoryDTO)result).setId(((TCategory)entity).getId());
                ((CategoryDTO)result).setDescription(((TCategory)entity).getDescription());
                ((CategoryDTO)result).setName(((TCategory)entity).getName());
            } 
            return result;
        }

    Выдавил из себя преобразование из Entity в DTO

    carapuz, 08 Марта 2015

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function array_search_my($string,$array){
            foreach($array as $el){
                if($el==$string) return true;
            }
            return false;
        }

    in_array - не круто.

    fasterrr, 06 Марта 2015

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

    −125

    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
    ТекущийПользователь = Справочники.Контрагенты.НайтиПоКоду(НовыйПользователь.Спонсор); //Выдергиваем указанного спонсора чтобы запихать ему в ногу
    Курсор = ТекущийПользователь.НастройкаКурсорНоги;//Определяет в какую ногу будут попадать новые рефералы
    Итератор = 0;
    
    Пока Истина цикл
    	Спонсор = ТекущийПользователь;//Небольшой финт
    	Если Итератор = 0 тогда
    		Если Курсор = "Левая" тогда
    			ТекущийПользователь = Справочники.Контрагенты.НайтиПоКоду(ТекущийПользователь.ЛеваяНога);
    		Иначе
    			ТекущийПользователь = Справочники.Контрагенты.НайтиПоКоду(ТекущийПользователь.ПраваяНога);
    		КонецЕсли;
    	Иначе
    		ТекущийПользователь = Справочники.Контрагенты.НайтиПоКоду(ТекущийПользователь.ПраваяНога); //Всех в "Правую ногу"
    	КонецЕсли;
    	
    	Если ТекущийПользователь = Справочники.Контрагенты.ПустаяСсылка тогда
    		Если Итератор = 0 тогда
    			Если Курсор = "Левая" тогда
    				Спонсор.ЛеваяНога = ТекущийПользователь;
    			Иначе
    				Спонсор.ПраваяНога = ТекущийПользователь;
    			КонецЕсли;
    		Иначе
    			Спонсор.ПраваяНога = ТекущийПользователь;
    		КонецЕсли;
    		Прервать;//Успешное завершение
    	КонецЕсли;
    КонецЦикла;

    Rijen, 05 Марта 2015

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

    +85

    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
    public final class Equality {
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @return true if the arguments are equal to each other and false otherwise
         */
        public static <O> boolean eq(@Nullable O o, @Nullable O a) {
            return Objects.equals(o, a);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a) {
            return eq(o, a);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b) {
            return eq(o, a) || eq(o, b);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c) {
            return eqAny(o, a, b) || eq(o, c);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @param d an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d) {
            return eqAny(o, a, b, c) || eq(o, d);
        }
    
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @param d an object to be compared with {@code o} for equality
         * @param e an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d, @Nullable O e) {
            return eqAny(o, a, b, c, d) || eq(o, e);
        }
        
        /**
         * @param o an object
         * @param a an array of objects to be compared
         * @return true if any the arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, O... a) {
            for(O e: a)
                if(eq(o, e))
                    return true;
            return false;
        }
    }

    Мой любимый класс.
    Когда на душе становится тяжело, я всегда открываю этот класс, и признаки депрессии улетучиваются.
    И да, комментарии врут, и да, там еще столько же методов eqAll(...)

    stasmarkin, 05 Марта 2015

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

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    there is a reason why opencart is the no.1 most used ecommerce solution in places like china and india, its the easiest code base to understand!
    
    --
    
    many apps servers! what does that mean? you mean different applications running from the same framework?
    you build each application starting from the index.php file and include what ever library classes you require.
    
    --
    
    "I agree with you that it's harder to write simple code, because REPEATING CODE IS HARD TO DEBUG HARD TO READ AND TO CORRECT. so it makes you waste a lot of time."
    
    this is what search and replace is for!

    Создатель опенкарта (Daniel Kerr) исходит на говно, много мякотки
    http://www.techchattr.com/never-use-opencart#comment-1151857248

    Fike, 22 Февраля 2015

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

    +51

    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
    //Sets the color(background and foreground)
    void Console::SetColor(){
        #ifdef _WIN32
            SetConsoleTextAttribute(hConsole, FGColor | BGColor);
        #else
            string clr = "\033[";
            clr += BGColor;
            clr += ";";
            clr += FGColor;
            clr += "m";
            cout << clr;
        #endif
    }

    Изменение цвета текста и фона консоли

    govnokod3r, 17 Февраля 2015

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

    +145

    1. 1
    2. 2
    char bStr[1000];
    strncpy(bStr, "  [\0", strlen("  [\0"));

    Потому что в man:
    Warning: If there is no null byte among the first n bytes of src, the string placed in dest will not be null terminated.

    Yeiradohr, 13 Февраля 2015

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

    +98

    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
    switch (_viewerPanel.Modified)
    {
         case true:
             _viewerPanel.FilenameLabel.Text = _listOfRecords[index].Name;
             _filesPanel.listViewControl.Items[index].Text = _listOfRecords[index].Name;
             _fileChangeDictionary[_listOfRecords[index].FullName] = true;
             break;
         case false:
             _viewerPanel.FilenameLabel.Text = _listOfRecords[index].Name;
             _filesPanel.listViewControl.Items[index].Text = _listOfRecords[index].Name;
             _fileChangeDictionary[_listOfRecords[index].FullName] = false;
             break;
    }

    Удивительно, но это писал не индус...

    dvgarays, 09 Февраля 2015

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