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

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

    +74

    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
    public class Encoder {
    	public static void encode(final OutputStream out, Node node) throws IOException {
    		node.accept(new NodeVisitor() {
    			@Override
    			public void string(StringNode node) {
    				byte[] value = node.toByteArray();
    				out.write(Integer.toString(value.length).getBytes(Constants.CHARSET));
    				out.write(':');
    				out.write(value);
    			}
                            // ... другие методы для других типов нод ...
                    }
            }
    }

    Решил поменять в паре-тройке модулей пачки ифов на паттерн visitor... И получил пинка от жабы ;(

    write() кидает IOException, а значит и метод string() в анонимном классе тоже должен кидать, и метод string() в интерфейсе NodeVisitor тоже... Но ведь соседним посетителям этот IOException нахер не сдался...

    Checked exceptions - зло.

    bormand, 12 Октября 2013

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

    +32

    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
    #include <iostream>
     
    void f(char c)          { std::cout << "f(char)" << std::endl; }
    void f(signed char c)   { std::cout << "f(signed char)" << std::endl; }
    void f(unsigned char c) { std::cout << "f(unsigned char)" << std::endl; }
     
    int main()
    {
            f('a');
            f((signed char)('a'));
            f((unsigned char)('a'));
            return 0;
    }

    илитный ресурс сегодня мне раскрыл глаза на очередное крестоблядство керниган-гай-ричи-блядство:
    с:
    The implementation shall define char to have the same range, representation, and behavior as either signed char or unsigned char.
    Irrespective of the choice made, char is a separate type from the other two and is not compatible with either.
    с++:
    Characters can be explicitly declared unsigned or signed. Plain char, signed char, and unsigned char are three distinct types.

    defecate-plusplus, 08 Октября 2012

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

    +26

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    result.push_back(TVector<2>
    				(
    					(A-√(D))/C,
    					(E-Line.K()*√(D))/C
    				));
    				result.push_back(TVector<2>
    				(
    					(A+√(D))/C,
    					(E+Line.K()*√(D))/C
    				));

    LispGovno, 31 Августа 2012

    Комментарии (55)
  5. Си / Говнокод #10987

    +141

    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
    ...
        ASSERT( sizeof(L"SystemPartition") <= sizeof(nameBuffer) );
    /* Китайский код? Или по другому нельзя было запихнуть строку в ентот массив? */
        nameBuffer[0]  = L'S';
        nameBuffer[1]  = L'y';
        nameBuffer[2]  = L's';
        nameBuffer[3]  = L't';
        nameBuffer[4]  = L'e';
        nameBuffer[5]  = L'm';
        nameBuffer[6]  = L'P';
        nameBuffer[7]  = L'a';
        nameBuffer[8]  = L'r';
        nameBuffer[9]  = L't';
        nameBuffer[10] = L'i';
        nameBuffer[11] = L't';
        nameBuffer[12] = L'i';
        nameBuffer[13] = L'o';
        nameBuffer[14] = L'n';
        nameBuffer[15] = L'\0';
    
        nameString.MaximumLength = sizeof(L"SystemPartition");
        nameString.Length        = sizeof(L"SystemPartition") - sizeof(WCHAR);
    
    
    
        status = NtSetValueKey(setupHandle,
                                &nameString,
                                TITLE_INDEX_VALUE,
                                REG_SZ,
                                volumeNameString.Buffer,
                                volumeNameString.Length + sizeof(WCHAR)
                               );
    ...

    В Мелкософт китайцев пригласили?

    Кусок кода ядра Шindoшs ИТ
    файл ioinit.c, строка 3312

    Destinat1on, 16 Июня 2012

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

    +107

    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
    begin
    writeln('Enter 1st number');
    readln(a);
    writeln('Enter 2st number');
    readln(b);
    writeln('Enter 3st number');
    readln(c);
    
    if a = b then if a = c then if b = c then       ;
    writeln('numbers are');
    
    if a > b then if a = c then if b < c then
    writeln('a Equally c and it is more b')         ;
    
    if a = b then if a > c then if b > c then
    writeln('a Equally b and it is more c')         ;
    
    if a < b then if a < c then if b = c then
    writeln('b Equally c and it is more a')         ;
    
    if a > b then if a > c then if b > c then
    writeln('a it is more ')                        ;
    if a > b then if a > c then if b < c then
    writeln('a it is more ')                        ;
    if a > b then if a > c then if b = c then
    writeln('a it is more ')                        ;
    
    if a < b then if a = c then if b > c then
    writeln('b it is more ')                        ;
    if a < b then if a > c then if b > c then
    writeln('b it is more ')                        ;
    if a < b then if a < c then if b > c then
    writeln('b it is more ')                        ;
    
    if a = b then if a < c then if b < c then
    writeln('c it is more ')                        ;
    if a > b then if a < c then if b < c then
    writeln('c it is more ')                        ;
    if a < b then if a < c then if b < c then
    writeln('c it is more ')                        ;

    Такое выдал один из моих учеников в 10м классе после того, как отказался учится рисовать блок-схемы и сказал, что сразу сможет писать. Задание заключалось в том, чтобы программа выводила большее из 3х введенных пользователем чисел.

    Rage, 20 Января 2012

    Комментарии (55)
  7. C# / Говнокод #8103

    +953

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    var result = System.Windows.Forms.MessageBox.Show("Ви дійсно бажаєте видалити платника?", "Видалення платників", System.Windows.Forms.MessageBoxButtons.YesNo);
    
    if (result == System.Windows.Forms.DialogResult.Yes)
    {
    DeleteWithoutRedirect(ReducingPayerID);
    red_pay_list.RemoveAt(e.RowIndex);
    }

    это Code-Behind aspx страницы
    Это писал "большой начальник" на укрПочте. Берегитесь Позывая. Он настолько суров, что гавнокодит сразу на 3 языках

    bercerker, 06 Октября 2011

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

    +164

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    inline ~Scene() {
        while( boxList.size() > 0 ) {
          boxList.erase( boxList.begin() );
        }
        while( sphereList.size() > 0 ) {
          sphereList.erase( sphereList.begin() );
        }
        while( lightList.size() > 0 ) {
          lightList.erase( lightList.begin() );
        }
      }

    http://www.gamedev.ru/code/forum/?id=136478&page=6#m82

    CPPGovno, 21 Сентября 2011

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

    +164

    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
    ULONG LCard791::SetChn(int _gain,int _channel)
    {
    		ULONG ret;
    		if(isDiff)
    				ret=_channel&15;
    		else
    		{
    				ret=_channel&31;
    				ret|=1<<5;
    		}
    		int gain;
    		switch(_gain)
    		{
    		case 1:
    				gain=0;
    				break;
    		case 2:
    				gain=1;
    				break;
    		case 4:
    				gain=2;
    				break;
    		case 8:
    				gain=3;
    				break;
    		case 16:
    				gain=4;
    				break;
    		case 32:
    				gain=5;
    				break;
    		case 64:
    				gain=6;
    				break;
    		case 128:
    				gain=7;
    				break;
    		default:
    				gain=0;
    		}
    		ret|=gain<<6;
    		return(ret);
    }

    Есть у нас один мужик, которые такие шедевры творит. Хакер сновидений, РАГ - мы с тобой!

    phys-tech, 02 Сентября 2011

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

    +131

    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
    if (comboBox1.SelectedItem.ToString() == "VISA")
                {
                    pictureBox7.Visible = false;
                    pictureBox6.Visible = false;
                    pictureBox5.Visible = false;
                    pictureBox4.Visible = false;
                    pictureBox3.Visible = false;
                    pictureBox2.Visible = false;
                    pictureBox1.Visible = true;
                }
                if (comboBox1.SelectedItem.ToString() == "MasterCard")
                {
                    pictureBox7.Visible = false;
                    pictureBox6.Visible = false;
                    pictureBox5.Visible = false;
                    pictureBox4.Visible = false;
                    pictureBox3.Visible = false;
                    pictureBox1.Visible = false;
                    pictureBox2.Visible = true;
                }

    + ещй пять такие проверок. Ну не умеет человек PictureBox.Image пользоваться.

    Killster, 16 Мая 2011

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

    +162

    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
    /*
        -----------------------------------------------------------------
        Маскировка ссылок в тексте
        -----------------------------------------------------------------
        */
        function antilink($var) {
            $var = preg_replace('~\\[url=(https?://.+?)\\](.+?)\\[/url\\]|(https?://(www.)?[0-9a-z\.-]+\.[0-9a-z]{2,6}[0-9a-zA-Z/\?\.\~&amp;_=/%-:#]*)~', '###', $var);
            $var = strtr($var, array (
                '.ru' => '***',
                '.com' => '***',
                '.biz' => '***',
                '.cn' => '***',
                '.in' => '***',
                '.net' => '***',
                '.org' => '***',
                '.info' => '***',
                '.mobi' => '***',
                '.wen' => '***',
                '.kmx' => '***',
                '.h2m' => '***'
            ));
    
            return $var;
        }

    JohnCMS 4, incfiles/classes/functions.php

    NadiaVita, 28 Декабря 2010

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