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

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

    +12

    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
    template<typename T, typename T1>
    	class TSwitch
    	{
    		private:
    			std::function<T1(T)> _functionSwitch;
    			std::function<void(T)> _defaultFunction;
    			std::map<T1, std::function<void(T)> > _map;
    		private:
    			IActorPtr _protocol;
    			IActorPtr _port;
    			IActorPtr _listParam;
    			IActorPtr _managerData;
    
    		public:
    		TSwitch(std::function<T1(T)> functionSwitch,std::map<T1, std::function<void(T)> > mapSwitch):_functionSwitch(functionSwitch)
    																									,_defaultFunction([](T value){std::cout<<"no way";})
    																									,_map(mapSwitch){}
    		TSwitch(std::function<T1(T)> functionSwitch, std::function<void(T)> defaultValue,std::map<T1, std::function<void(T)> > mapSwitch):_functionSwitch(functionSwitch)
    																																		,_defaultFunction(defaultValue)																																,_map(mapSwitch){}
    		virtual ~TSwitch(){}
    		public:
    			void switches(T value)
    			{
    				auto it=_map.find(_functionSwitch(value));
    				if (it==_map.end()) {_defaultFunction(value); return;}
    				it->second(value);
    			}
    	};

    Вот такая замена switch. Отстойно не правда-ли?

    IKing, 29 Мая 2014

    Комментарии (6)
  3. Ruby / Говнокод #16072

    −136

    1. 1
    2. 2
    3. 3
    4. 4
    it 'traders email should be nil' do
       trader = FactoryGirl.create(:trader, :email => nil)
       trader.email.should be nil
    end

    captain obvious test

    andrejlr, 28 Мая 2014

    Комментарии (6)
  4. Pascal / Говнокод #16056

    +83

    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
    var
      ABuffer: PAnsiChar;
      AText: PAnsiChar;
      BBuffer: PAnsiChar;
    begin
      ABuffer := 'TEST';
      BinToHex(ABuffer, AText, Length(ABuffer));
      ShowMessage(AText);
      ShowMessage(IntToStr(Length(AText)));
      GetMem(BBuffer, Length(AText) div 2);
      HexToBin(AText, BBuffer, Length(AText) div 2);
      BBuffer[Length(BBuffer) - 1] := #0;
      ShowMessage(IntToStr(SizeOf(BBuffer)));
      ShowMessage(BBuffer);
      FreeMem(BBuffer);
    end;

    http://www.sql.ru/forum/653685/bintohex-i-hextobin-delphi2009
    Возможно, я ошибаюсь, но по-моему код - лажа; насколько я понимаю, указатель "AText: PAnsiChar;" всего лишь УКАЗАТЕЛЬ, под него нигде в коде не выделяется память, автор юзает его как простую переменную.
    И никто его не поправил. Вроде думающие люди.

    brutushafens, 25 Мая 2014

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

    +134

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    private byte Summ(byte a, byte b, byte p)
            {
    
                return Or(Or(Or(And(p, Not(a)), And(p, Not(b))), Or(And(b, Not(a)), And(b, Not(a))))Or(And(a, Not(b)),And(a, Not(p))), ()) ;//тут я и сломался 
             
            }

    Shadowy1, 17 Мая 2014

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

    +69

    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
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    package com.javarush.test.level06.lesson11.bonus02;
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
     
    /* Нужно добавить в программу новую функциональность
    Задача: У каждой кошки есть имя и кошка-мама. Создать класс, который бы описывал данную ситуацию. Создать два объекта: кошку-дочь и кошку-маму. Вывести их на экран.
    Новая задача: У каждой кошки есть имя, кошка-папа и кошка-мама. Изменить класс Cat так, чтобы он мог описать данную ситуацию.
    Создать 6 объектов: маму, папу, сына, дочь, бабушку(мамина мама) и дедушку(папин папа).
    Вывести их всех на экран в порядке: дедушка, бабушка, папа, мама, сын, дочь.
     
    Пример ввода:
    дедушка Вася
    бабушка Мурка
    папа Котофей
    мама Василиса
    сын Мурчик
    дочь Пушинка
     
    Пример вывода:
    Cat name is дедушка Вася, no mother, no father
    Cat name is бабушка Мурка, no mother, no father
    Cat name is папа Котофей, no mother, father is дедушка Вася
    Cat name is мама Василиса, mother is бабушка Мурка, no father
    Cat name is сын Мурчик, mother is мама Василиса, father is папа Котофей
    Cat name is дочь Пушинка, mother is мама Василиса, father is папа Котофей
    */
     
    public class Solution
    {
        public static void main(String[] args) throws IOException
        {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
     
            String grfatherName = reader.readLine();
            Cat catGrfather = new Cat(grfatherName);
     
            String grmotherName = reader.readLine();
            Cat catGrmother = new Cat(grmotherName);
     
            String fatherName = reader.readLine();
            Cat catFather = new Cat(fatherName, catGrfather, null);
     
            String motherName = reader.readLine();
            Cat catMother = new Cat(motherName, null, catGrmother);
     
            String sonName = reader.readLine();
            Cat catSon = new Cat(sonName, catFather, catMother);
     
            String daughterName = reader.readLine();
            Cat catDaughter = new Cat(daughterName, catFather, catMother);
     
            System.out.println(catGrfather);
            System.out.println(catGrmother);
            System.out.println(catFather);
            System.out.println(catMother);
            System.out.println(catSon);
            System.out.println(catDaughter);
     
        }
     
        public static class Cat
        {
            private String name;
            private Cat father;
            private Cat mother;
     
     
            Cat(String name)
            {
                this.name = name;
            }
     
            Cat (String name, Cat father, Cat mother){
                this.name = name;
                this.mother = mother;
                this.father = father;
     
            }
     
            @Override
            public String toString()
            {
                if ((mother == null) && (father == null))
                    return "Cat name is " + name + ", no mother, no father ";
                else if (father == null)
                    return "Cat name is " + name + ", mother is " + mother.name + " , no father";
                else if (mother == null)
                    return  "Cat name is " + name + ", no mather " + ", father is " + father.name;
                else
                    return "Cat name is " + name + ", mother is " + mother.name + ", father is " + father.name;
            }
        }
    }

    Да лаба, точнее задание. Но меня так умиляет решение задачи :) Просто немного хардкода :)

    kostoprav, 15 Мая 2014

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

    +73

    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
    public static int getWordCount(String getInput, int e){
        int numberOfWords = 0;
        char l1 = 0;
        char l2 = 0;
        StringBuilder convertInput = new StringBuilder(getInput);
        System.out.println(convertInput);
        for (int i = 0, i1 = 1; i < getInput.length();i++, i1++){
            l2 = convertInput.charAt(i);
            if (l2 == ' '){
                numberOfWords += 1;
                l1 = convertInput.charAt(i1);
            }
            if (i == getInput.length() - 1){
                numberOfWords += 1;
            }
            if (l2 == ' ' && l1 == ' '){
                numberOfWords -= 1;
            }
        }
        return numberOfWords;
     } // end of getWordCount method

    http://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html да и просто регексп на крайняк как видно запрещены религией.

    kostoprav, 13 Мая 2014

    Комментарии (6)
  8. JavaScript / Говнокод #15969

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function test(x) {
        function undefined(x) { throw "Missing in action"; }
        switch (x) {
        case 1: console.log("X reporting for duty!"); break;
        case undefined(x): break;
        }
    }

    Переделка длинного и скучного кода, но смысл остался.

    wvxvw, 13 Мая 2014

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

    +75

    1. 1
    return new Integer(((Integer)var).intValue()+1);

    Autoboxing? Не, не слышал...

    kostoprav, 08 Мая 2014

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

    +17

    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
    cKeyCfg::types_t cConfiguration::SearchInType(string type)
    {
        CTint i = 0;
        const CTbyte * types[] = { "S", "D" };
    
        for(i = 0; i < sizeof(types)/sizeof(types[0]); i++) {
          if ( strcmp(type.c_str(),types[i]) == 0) {
            switch (i) {
            case 0: // Is string
              return cKeyCfg::stringa;
            case 1: // Is decimal
              return cKeyCfg::decimale;
            default: //Default value VT_BSTR
              return cKeyCfg::unknow;
            }
          }
        }
        return cKeyCfg::unknow;
    }

    сделано на родине Fiat'а.

    Dummy00001, 02 Мая 2014

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

    +134

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    try{
        tempPage1Int = tempPage1.ToInt();
      }catch(Exception &E){
        tempPage1Int = 0;
        goto NEXTFUCKER;
      }
      NEXTFUCKER:

    Дописываю из-под стола.

    dm-ua, 30 Апреля 2014

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