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

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

    +106

    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
    procedure Tform1.mix;
    begin
     randomize;
     a[1]:=random(16)+1;
     btn[1].Caption:=inttostr(a[1]);
    begin
    repeat
     a[2]:=random(16)+1
    until
     a[2]<>a[1];
     btn[2].Caption:=inttostr(a[2]);
    begin
    repeat
     a[3]:=random(16)+1
    until
     (a[3]<>a[2]) and (a[3]<>a[1]);
     btn[3].Caption:=inttostr(a[3]);
    begin
    repeat
     a[4]:=random(16)+1
    until
     (a[4]<>a[2]) and (a[4]<>a[1]) and (a[4]<>a[3]);
     btn[4].Caption:=inttostr(a[4]);
    begin
    repeat
     a[5]:=random(16)+1
    until
     (a[5]<>a[2]) and (a[5]<>a[1]) and (a[5]<>a[3]) and (a[5]<>a[4]);
     btn[5].Caption:=inttostr(a[5]);
    begin
    repeat
     a[6]:=random(16)+1
    until
     (a[6]<>a[1]) and (a[6]<>a[2]) and (a[6]<>a[3]) and (a[6]<>a[4])
     and (a[6]<>a[5]);
     btn[6].Caption:=inttostr(a[6]);
    begin
    repeat
     a[7]:=random(16)+1
    until
     (a[7]<>a[1]) and (a[7]<>a[2]) and (a[7]<>a[3]) and
     (a[7]<>a[4]) and (a[7]<>a[5]) and (a[7]<>a[6]);
     btn[7].Caption:=inttostr(a[7]);
    begin
    repeat
     a[8]:=random(16)+1
    until
     (a[8]<>a[1]) and (a[8]<>a[2]) and (a[8]<>a[3]) and
     (a[8]<>a[4]) and (a[8]<>a[5]) and (a[8]<>a[6]) and (a[8]<>a[7]);
     btn[8].Caption:=inttostr(a[8]);
    begin
    repeat
     a[9]:=random(16)+1
    until
     (a[9]<>a[1]) and (a[9]<>a[2]) and (a[9]<>a[3]) and (a[9]<>a[4]) and
     (a[9]<>a[5]) and (a[9]<>a[6]) and (a[9]<>a[7]) and (a[9]<>a[8]);
     btn[9].Caption:=inttostr(a[9]);
    ...
    ...
    ...
    begin
    repeat
     a[14]:=random(16)+1
    until
     (a[14]<>a[1]) and (a[14]<>a[2]) and (a[14]<>a[3])
     and (a[14]<>a[4]) and (a[14]<>a[6]) and
     (a[14]<>a[7]) and (a[14]<>a[5]) and (a[14]<>a[9])
     and (a[14]<>a[8]) and (a[14]<>a[10]) and
     (a[14]<>a[11]) and (a[14]<>a[12]) and (a[14]<>a[13]);
     btn[14].Caption:=inttostr(a[14]);
    begin
    repeat
     a[15]:=random(16)+1
    until
     (a[15]<>a[1]) and (a[15]<>a[2]) and (a[15]<>a[3]) and
     (a[15]<>a[4]) and (a[15]<>a[6]) and (a[15]<>a[7]) and
     (a[15]<>a[5]) and (a[15]<>a[9]) and (a[15]<>a[8]) and
     (a[15]<>a[10]) and (a[15]<>a[11]) and (a[15]<>a[12])
     and (a[15]<>a[13]) and (a[15]<>a[14]);
     btn[15].Caption:=inttostr(a[15]);
    begin
    repeat
     a[16]:=random(16)+1
    until
     (a[16]<>a[1]) and (a[16]<>a[2]) and (a[16]<>a[3]) and
     (a[16]<>a[4]) and (a[16]<>a[6]) and (a[16]<>a[7]) and
     (a[16]<>a[5]) and (a[16]<>a[9]) and (a[16]<>a[8]) and
     (a[16]<>a[10]) and (a[16]<>a[11]) and (a[16]<>a[12])
     and (a[16]<>a[13]) and (a[16]<>a[14]) and (a[16]<>a[15]);
     btn[16].Caption:=inttostr(a[16]);
     timer3.Enabled:=true;
    end; end; end; end; end; end; end; end; end;
    end; end; end; end; end; end; end;

    Это у меня однокурсник писал пятнашки(данная процедура заполняет массив неповторяющимися числами от одного пятнадцати), и не лень же ему было...

    suc-daniil, 14 Октября 2011

    Комментарии (77)
  3. Си / Говнокод #7493

    +106

    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
    if (fFisWaitAccept)
        {
            if (++countB > 2)
            {
                countB = 0;
                TRACE("ERROR TIMER B\n");
                Reinit_ATS_Connection();
                fFisWaitAccept = false;
                set_timer_b(tmB);
                return;
            }
        }
        else
            countB = 0;
        SendFrameToATS(buf, 4);        //visilaem neskolko raz
        SendFrameToATS(buf, 4);        //FW dlia bolshej uverennosti
        SendFrameToATS(buf, 4);        //ibo esli etot paket nedojdiot sviazi pizdec
        fFisWaitAccept = true;
        set_timer_b(tmB);

    Фрагмент кода управляющей программы для некоей АТС.

    b10876198, 09 Августа 2011

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

    +106

    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
    function TmainForm1.getLetterFinger( letter: String ): Integer;
    begin
      letter := UpperCase( letter );
      if ( letter = 'Ё' ) or ( letter = '1' ) or ( letter = 'Й' ) or
        ( letter = 'Ф' ) or ( letter = 'Я' ) or ( letter = '~' ) or
        ( letter = '!' ) or ( letter = 'Q' ) or ( letter = 'A' ) or
        ( letter = 'Z' ) or ( letter = 'LSHIFT' ) or ( letter = 'LCTRL' ) or
        ( letter = 'TAB' ) or ( letter = 'CAPS' ) or ( letter = 'SHIFT' ) then
        Result := 1;
      if ( letter = '2' ) or ( letter = '@' ) or ( letter = '"' ) or
        ( letter = 'W' ) or ( letter = 'S' ) or ( letter = 'X' ) or
        ( letter = 'Ц' ) or ( letter = 'Ы' ) or ( letter = 'Ч' ) then
        Result := 2;
      if ( letter = '3' ) or ( letter = '№' ) or ( letter = '#' ) or
        ( letter = 'E' ) or ( letter = 'D' ) or ( letter = 'C' ) or
        ( letter = 'У' ) or ( letter = 'В' ) or ( letter = 'С' ) then
        Result := 3;
      if ( letter = '4' ) or ( letter = ';' ) or ( letter = '$' ) or
        ( letter = 'R' ) or ( letter = 'F' ) or ( letter = 'V' ) or
        ( letter = 'К' ) or ( letter = 'А' ) or ( letter = 'М' ) or
        ( letter = '5' ) or ( letter = '%' ) or ( letter = 'Е' ) or
        ( letter = 'П' ) or ( letter = 'И' ) or ( letter = 'Е' ) or
        ( letter = 'T' ) or ( letter = 'G' ) or ( letter = 'B' ) then
        Result := 4;
      if ( letter = 'LSPACE' ) or ( letter = 'LATL' ) then
        Result := 5;
      if ( letter = 'RSPACE' ) or ( letter = 'RATL' ) then
        Result := 6;
      if ( letter = '&' ) or ( letter = '?' ) or ( letter = '7' ) or
        ( letter = 'Y' ) or ( letter = 'U' ) or ( letter = 'H' ) or
        ( letter = 'J' ) or ( letter = 'N' ) or ( letter = 'M' ) or
        ( letter = 'Н' ) or ( letter = 'Г' ) or ( letter = 'Р' ) or
        ( letter = 'О' ) or ( letter = 'Т' ) or ( letter = 'Ь' ) then
        Result := 7;
      if ( letter = '8' ) or ( letter = '*' ) or ( letter = 'Ш' ) or
        ( letter = 'Л' ) or ( letter = 'Б' ) or ( letter = ',' ) or
        ( letter = '<' ) or ( letter = 'K' ) or ( letter = 'I' ) then
        Result := 8;
      if ( letter = '9' ) or ( letter = '(' ) or ( letter = 'O' ) or
        ( letter = 'L' ) or ( letter = '.' ) or ( letter = '>' ) or
        ( letter = 'Щ' ) or ( letter = 'Д' ) or ( letter = 'Ю' ) then
        Result := 9;
      if ( letter = '0' ) or ( letter = ')' ) or ( letter = '-' ) or
        ( letter = '_' ) or ( letter = '+' ) or ( letter = '=' ) or
        ( letter = 'BACKSPACE' ) or ( letter = 'ENTER' ) or
        ( letter = 'RSHIFT' ) or ( letter = 'P' ) or ( letter = '{' ) or
        ( letter = '[' ) or ( letter = '}' ) or ( letter = ']' ) or
        ( letter = ':' ) or ( letter = ';' ) or ( letter = '''' ) or
        ( letter = '"' ) or ( letter = '/' ) or ( letter = '?' ) or
        ( letter = '\' ) or ( letter = '/' ) or ( letter = '?' ) or
        ( letter = '|' ) or ( letter = 'Ж' ) or ( letter = 'Э' ) or
        ( letter = '.' ) or ( letter = ',' ) or ( letter = 'З' ) or
        ( letter = 'Х' ) or ( letter = 'Ъ' ) then
        Result := 10;
    
    end;

    Nuff said.

    Fai, 30 Июля 2011

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

    +106

    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
    public static bool KeyToString(Keys key, bool shitKeyPressed,
                                                                        out char character)
            {
                bool result = false;
                character = ' ';
                CharPair charPair;
    
                if ((Keys.A <= key && key <= Keys.Z) || key == Keys.Space)
                {
                    // Use as is if it is A~Z, or Space key.
                    character = (shitKeyPressed) ? (char)key : Char.ToLower((char)key);
                    result = true;
                }
                else if (keyMap.TryGetValue(key, out charPair))
                {
                    // Otherwise, convert by key map.
                    if (!shitKeyPressed)
                    {
                        character = charPair.NormalChar;
                        result = true;
                    }
                    else if (charPair.ShiftChar.HasValue)
                    {
                        character = charPair.ShiftChar.Value;
                        result = true;
                    }
                }
    
                return result;
            }

    Разбираю код, скачанный с майкросовтовского App Hub. В коде и комментариях полно маленьких грамматический ошибок, но это...
    Код выложен на полном серьёзе и качается тут http://create.msdn.com/en-US/education/catalog/utility/performance_utility

    P.S. для тупых спойлер: вместо shift написано shit.

    Skelet0n, 23 Февраля 2011

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

    +106

    1. 1
    2. 2
    if not FileExists(aFileName) then
        raise Exception('Не удалось загрузить тесты. Файл "' + aFileName + '" не найден.');

    Долго думал почему возникает Access violation, а не то, что нужно.

    AK-47, 30 Декабря 2010

    Комментарии (16)
  7. Pascal / Говнокод #5022

    +106

    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
    function IsRunningWithAdminPrivs: Boolean;
    begin
    var
      List: TStringList;
    begin
      List := TStringList.Create;
      try
        try
          List.Text := 'Sample';
          // Use SHGetFolder path to retreive the program files folder
          // here is hardcoded for the sake of the example
          List.SaveToFile('C:\program files\test.txt');
          Result := True;
        except
          Result := False;
        end;
      finally
        List.Free;
        DeleteFile('C:\program files\test.txt');
      end;
    end;

    Нуфф Саид

    bugmenot, 22 Декабря 2010

    Комментарии (63)
  8. Pascal / Говнокод #4646

    +106

    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
    procedure FirstStep (var Text: string);
    // Удаление комментариев <!--...-->, переводов строк, раскрытие тегов <br>, удаление парных пробелов:
    var
      P:     Integer;
      State: Integer;
      Idx:   Integer;
      Cnt:   Integer;
      NL:    Boolean;
    begin
      State := 0;
      P     := 1;
      NL    := True;
      while P <= Length (Text) do
      begin
        if Text[P] in [#9,#10,#13] then Text[P] := ' ';
        case State of
          0: case Text[P] of
               '<': State := 1;
               ' ': begin
                      Idx := P;
                      State := 9;
                    end; { }
               else NL := False;
             end; {case}
          1: case Text[P] of
               '!': State := 2;
               'b': State := 7;
               else
               begin
                 Dec (P);
                 State := 10;
               end; {else}
             end; {case}
          2: if Text[P] <> '-' then
             begin
               Dec (P);
               State := 10;
             end else State := 3;
          3: if Text[P] = '-' then
             begin
               Idx   := P - 3;
               State := 4;
             end else
             begin
               Dec (P);
               State := 10;
             end; {if}
          4: if Text[P] = '-' then State := 5;
          5: if Text[P] = '-' then State := 6 else State := 4;
          6: if Text[P] = '>' then
             begin
               Delete (Text, Idx, P - Idx + 1);
               P := Idx - 1;
               while (P >= 1) and (Text[P] = ' ') do Dec (P);
               State := 0;
             end else State := 4;
          7: if Text[P] = 'r' then State := 8 else State := 0;
          8: begin
               if Text[P] = '>' then
               begin
                 Text[P-3] := #13;
                 Text[P-2] := #10;
                 Delete (Text, P - 1, 2);
                 Dec (P, 2);
                 NL := True;
               end; {if}
               State := 0;
             end; {8}
          9: if Text[P] <> ' ' then
             begin
               Cnt := P - Idx;
               if NL then
               begin
                 Delete (Text, Idx, Cnt);
                 Dec (Idx);
               end else if Cnt > 1 then Delete (Text, Idx, Cnt - 1);
               P := Idx;
               State := 0;
             end; {if}
          10: if Text[P] = '>' then State := 0;
        end; {case}
        Inc (P);
      end; {while}
    end; {proc FirstStep}

    Кусок парсера HTML.

    Arigato, 16 Ноября 2010

    Комментарии (38)
  9. Pascal / Говнокод #4558

    +106

    1. 1
    2. 2
    3. 3
    FilterKey = 'Software'+'\'+CompanyName+'\'+ApplName+'\'+ApplVersion+'\'+SettingsKey+'\'+'FilterDD';
    OrderKey = 'Software'+'\'+CompanyName+'\'+ApplName+'\'+ApplVersion+'\'+SettingsKey+'\'+'OrderDD';
    NotepadKey = 'Software'+'\'+CompanyName+'\'+ApplName+'\'+ApplVersion+'\'+SettingsKey+'\'+'Notepad';

    повторение - мать учения

    gorsash, 08 Ноября 2010

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

    +106

    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
    // процедура ввода новой даты в RTC
    long __new_date()
    	{
    	date sysdate;
    	unsigned long str,i;
    	unsigned char tmpbuf[16];
    
    // ...
    
    nextda:	__putsV("\n\rВведите новую дату: ");
    	__getsV(tmpbuf,10); 
    	if(tmpbuf[0]==0) goto daok;
    	//проверка строки на допустимые символы '0'-'9' и '.'
    	for(i=0; tmpbuf[i]!=0; i++)
    	 { if((tmpbuf[i]>0x39 || tmpbuf[i]<0x30) && tmpbuf[i]!=0x2e) goto baddat;
    	 }
    	//проверка числа в диапазоне 01-31
    	if(((tmpbuf[0]==0x33)&&(tmpbuf[1]>0x31)) || (tmpbuf[0]>0x33) 
    		|| (tmpbuf[1]==0x2e) || ((tmpbuf[0]==0x30)&&(tmpbuf[1]==0x30)) ) goto baddat;
    	//проверка точки после числа
    	if((tmpbuf[2]!=0x2e) && (tmpbuf[2]!=0x0)) goto baddat; 
    	if((tmpbuf[2]==0x0) || (tmpbuf[3]==0x00)) 
    		{ sysdate.ti_date=(tmpbuf[1]-0x30)+((tmpbuf[0]-0x30)<<4);
    		  goto fordok; }
    	//проверка месяца в диапазоне 01-12
    	if(((tmpbuf[3]==0x31)&&(tmpbuf[4]>0x32)) || (tmpbuf[3]>0x31) 
    		|| (tmpbuf[4]==0x2e) || ((tmpbuf[3]==0x30)&&(tmpbuf[4]==0x30)) ) goto baddat;
    	//проверка точки после месяца
    	if((tmpbuf[5]!=0x2e) && (tmpbuf[5]!=0x0)) goto baddat; 
    	if((tmpbuf[5]==0x0) || (tmpbuf[6]==0x00)) 
    		{ sysdate.ti_date=(tmpbuf[1]-0x30)+((tmpbuf[0]-0x30)<<4);
    		  sysdate.ti_month=(tmpbuf[4]-0x30)+((tmpbuf[3]-0x30)<<4); 
    		  goto fordok; }
    	//проверка года в диапазоне 00-99
    	if((tmpbuf[6]==0x2e) || (tmpbuf[7]==0x2e)) goto baddat;
    	if(tmpbuf[7]==0x00) goto baddat; 
    	if(tmpbuf[8]==0x0)  
    		{ sysdate.ti_date=(tmpbuf[1]-0x30)+((tmpbuf[0]-0x30)<<4);
    		  sysdate.ti_month=(tmpbuf[4]-0x30)+((tmpbuf[3]-0x30)<<4); 
    		  sysdate.ti_year=(tmpbuf[7]-0x30)+((tmpbuf[6]-0x30)<<4); 
    		  goto fordok; }
    baddat:	__putsV("\n\rДата введена неверно (дд.мм.гг)");
    	goto nextda;
    	//установка новой даты
    fordok: 
    	__set_date(&sysdate);
    daok: 
       return 0;
    	}

    Из ПО отечественного шифродевайса. Функция получает от "оператора" время (дд.мм.гг), проверяет его на корректность и пишет в Real Time Clock.

    greyspy, 03 Ноября 2010

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

    +106

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    proxy1.GetMeasurements(
                new AccountingMeasurementType(255, "Тип документа")))
                            .ToList()
                            .FirstOrDefault(item => 
                                        item.Name.Equals("Спецификация")
                            ),
                SpecificationDS.DateFrom as DateTime?,
                SpecificationDS.DateTo as DateTime?)
    );

    Мало того что в коде прошита сразу куча строк, так еще и числовая константа %)

    User123, 08 Июня 2010

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