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

    В номинации:
    За время:
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. Си / Говнокод #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)
  9. 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)
  10. Assembler / Говнокод #17539

    +145

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    add ax,1 ; Добавляем в ax 1 (не знаю, почему он так сделал, МЕДЛЕННО И 3 БАЙТА), можно было же inc ax
    add ax,1
    add ax,1
    add ax,1
    add ax,1
    add ax,1
    add ax,1
    add ax,1
    add ax,1
    mov ax,9 ; А теперь я понял тщетность бытия и те потраченные байты выше.

    Самый лучший говнокод новичка, который я видел.

    Mihip, 28 Января 2015

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

    +95

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static class ColorExtension
    	{
    		public static bool IsDarkColor(this Color color)
    		{
    			return (color.R & 255) + (color.G & 255) + (color.B & 255) < 3*256/2;
    		}
    	}

    x & 255 = ?, где x типа byte

    schecterXA, 22 Января 2015

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