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

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

    +136

    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
    if(GUI.Button(Rect(100,50,50,50),NewTexture[0])) 
    { Change = true; Clicks += 1; GridNumber = 0;   }
    if(GUI.Button(Rect(150,50,50,50),NewTexture[1])) 
    { Change = true; Clicks += 1; GridNumber = 1;   }
    if(GUI.Button(Rect(200,50,50,50),NewTexture[2])) 
    { Change = true; Clicks += 1; GridNumber = 2;   }
    if(GUI.Button(Rect(250,50,50,50),NewTexture[3])) 
    { Change = true; Clicks += 1; GridNumber = 3;   }
    if(GUI.Button(Rect(300,50,50,50),NewTexture[4])) 
    { Change = true; Clicks += 1; GridNumber = 4;   }
    if(GUI.Button(Rect(350,50,50,50),NewTexture[5])) 
    { Change = true; Clicks += 1; GridNumber = 5;   }
    if(GUI.Button(Rect(400,50,50,50),NewTexture[6])) 
    { Change = true; Clicks += 1; GridNumber = 6;   }
    if(GUI.Button(Rect(100,100,50,50),NewTexture[7])) 
    { Change = true; Clicks += 1; GridNumber = 7;   }
    if(GUI.Button(Rect(150,100,50,50),NewTexture[8])) 
    { Change = true; Clicks += 1; GridNumber = 8;   }
    if(GUI.Button(Rect(200,100,50,50),NewTexture[9])) 
    { Change = true; Clicks += 1; GridNumber = 9;   }
    if(GUI.Button(Rect(250,100,50,50),NewTexture[10])) 
    { Change = true; Clicks += 1; GridNumber = 10;  }
    if(GUI.Button(Rect(300,100,50,50),NewTexture[11])) 
    { Change = true; Clicks += 1; GridNumber = 11;  }
    if(GUI.Button(Rect(350,100,50,50),NewTexture[12])) 
    { Change = true; Clicks += 1; GridNumber = 12;  }
    if(GUI.Button(Rect(400,100,50,50),NewTexture[13])) 
    { Change = true; Clicks += 1; GridNumber = 13;  }
    if(GUI.Button(Rect(100,150,50,50),NewTexture[14])) 
    { Change = true; Clicks += 1; GridNumber = 14;  }
    if(GUI.Button(Rect(150,150,50,50),NewTexture[15])) 
    { Change = true; Clicks += 1; GridNumber = 15;  }
    if(GUI.Button(Rect(200,150,50,50),NewTexture[16])) 
    { Change = true; Clicks += 1; GridNumber = 16;  }
    if(GUI.Button(Rect(250,150,50,50),NewTexture[17])) 
    { Change = true; Clicks += 1; GridNumber = 17;  }
    if(GUI.Button(Rect(300,150,50,50),NewTexture[18])) 
    { Change = true; Clicks += 1; GridNumber = 18;  }
    if(GUI.Button(Rect(350,150,50,50),NewTexture[19])) 
    { Change = true; Clicks += 1; GridNumber = 19;  }
    if(GUI.Button(Rect(400,150,50,50),NewTexture[20])) 
    { Change = true; Clicks += 1; GridNumber = 20;  }
    if(GUI.Button(Rect(100,200,50,50),NewTexture[21])) 
    { Change = true; Clicks += 1; GridNumber = 21;  }
    if(GUI.Button(Rect(150,200,50,50),NewTexture[22])) 
    { Change = true; Clicks += 1; GridNumber = 22;  }
    if(GUI.Button(Rect(200,200,50,50),NewTexture[23])) 
    { Change = true; Clicks += 1; GridNumber = 23;  }
    if(GUI.Button(Rect(250,200,50,50),NewTexture[24])) 
    { Change = true; Clicks += 1; GridNumber = 24;  }
    if(GUI.Button(Rect(300,200,50,50),NewTexture[25])) 
    { Change = true; Clicks += 1; GridNumber = 25;  }
    if(GUI.Button(Rect(350,200,50,50),NewTexture[26])) 
    { Change = true; Clicks += 1; GridNumber = 26;  }
    if(GUI.Button(Rect(400,200,50,50),NewTexture[27])) 
    { Change = true; Clicks += 1; GridNumber = 27;  }
    if(GUI.Button(Rect(100,250,50,50),NewTexture[28])) 
    { Change = true; Clicks += 1; GridNumber = 28;  }
    if(GUI.Button(Rect(150,250,50,50),NewTexture[29])) 
    { Change = true; Clicks += 1; GridNumber = 29;  }
    if(GUI.Button(Rect(200,250,50,50),NewTexture[30])) 
    { Change = true; Clicks += 1; GridNumber = 30;  }
    if(GUI.Button(Rect(250,250,50,50),NewTexture[31])) 
    { Change = true; Clicks += 1; GridNumber = 31;  }
    if(GUI.Button(Rect(300,250,50,50),NewTexture[32])) 
    { Change = true; Clicks += 1; GridNumber = 32;  }
    if(GUI.Button(Rect(350,250,50,50),NewTexture[33])) 
    { Change = true; Clicks += 1; GridNumber = 33;  }
    if(GUI.Button(Rect(400,250,50,50),NewTexture[34])) 
    { Change = true; Clicks += 1; GridNumber = 34;  }
    if(GUI.Button(Rect(400,350,50,50),NewTexture[40])) 
    { Change = true; Clicks += 1; GridNumber = 40;  }
    if(GUI.Button(Rect(450,350,50,50),NewTexture[41])) 
    { Change = true; Clicks += 1; GridNumber = 41;  }
    if(GUI.Button(Rect(500,350,50,50),NewTexture[42])) 
    { Change = true; Clicks += 1; GridNumber = 42;  }
    ...
    if(GUI.Button(Rect(100,550,65,65),NewTexture[35])) 
    { Change = true; Clicks += 1; GridNumber = 35; }
    if(GUI.Button(Rect(165,550,65,65),NewTexture[36])) 
    { Change = true; Clicks += 1; GridNumber = 36; }
    if(GUI.Button(Rect(230,550,65,65),NewTexture[37])) 
    { Change = true; Clicks += 1; GridNumber = 37; }
    if(GUI.Button(Rect(295,550,65,65),NewTexture[38])) 
    { Change = true; Clicks += 1; GridNumber = 38; }
    if(GUI.Button(Rect(360,550,65,65),NewTexture[39])) 
    { Change = true; Clicks += 1; GridNumber = 39; }

    http://answers.unity3d.com/questions/691870/gui-button-not-showing-up.html

    dzzpchelka, 12 Сентября 2014

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

    +136

    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
    string delnbsp(string str)
            {
                int k;
                while (str.IndexOf(" ") >= 0)
                {
                    k = str.IndexOf(" ");
                    str = str.Remove(k, 6);
                }
    
                while (str.IndexOf(",") >= 0)
                {
                    k = str.IndexOf(",");
                    str = str.Remove(k, 1);
                }
                while (str.IndexOf("results") >= 0)
                {
                    k = str.IndexOf("results");
                    str = str.Remove(k, 7);
                }
                while (str.IndexOf(" ") >= 0)
                {
                    k = str.IndexOf(" ");
                    str = str.Remove(k, 1);
                }
    
                return str;
    
            }

    Кандидат решал тестовое задание на с#.

    dima054, 19 Июля 2014

    Комментарии (29)
  4. Си / Говнокод #16375

    +136

    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
    #include studio.h
    
    main()
    {
      uint16 final,num;
      printf(“enetr the unsigned integer 16bit number “);
      scanf(“%d”, &num);
      final= numbitset(num);
      printf(“%d”, final);
    }
    
    unit16 numbitset( unit16 x)
    {
      int i, j,result, total=0;
      uint16 no,modify
      for(i=1;i<=4;i++)
      {
        j=pow(10,i);
        no= (x%(j))>>(i-1)*4;
        if(no==0)
        {
          result=0;
        }
        else if(no==1)
        {
          result=1;
        }
        else if(no==2)
        {
          result=1;
        }
        else if(no==3)
        {
          result=2;
        }
       else
       {
          result = othernum(no/4)+othernum(no%4);	
        }
        total = total+result;
      }
    }
    
    uint16 othernum( uint16 y)
    {
      switch(y)
      {
        case 0:
          return(0);
          break;
      case 1:
          return(1);
         break;
      case 2:
        return(1);
        break;
       case 3:
          return(2);
          break;
       default:
        return;
        break;
      }
    }

    Посчитать количество значащиз битов в 16ти разрядном целом. Реальный тест на собеседовании дал такой вот результат. Угадайте откуда кандидат :)

    multilexa, 18 Июля 2014

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

    +136

    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
    void lcd_show(uint8_t number)
    {
        uint8_t digit3 = 0;
        uint8_t digit2 = 0;
        uint8_t digit1 = number > 99u ? 1u : 0;
    
        switch(number)
        {
            case 0u: 
                digit3 = 0u;
                digit2 = 0u;
            break;
            case 1u: 
                digit3 = 1u;
                digit2 = 0u;
            break;
    .....
    .....
            case 199u: 
                digit3 = 9u;
                digit2 = 9u;
            break;
            default:
                digit3 = '-';
                digit2 = '-';
                digit1 = 0;
            break;
        }
    
        display3d(digit3);
        display2d(digit2);
        display1d(digit1);
    }

    8-битный микроконтроллер, 32768Гц тактовая частота, батарейное питание, CPU по-максимуму в спячке для экономии энергии.
    Функции display3d(), display2d(), display1() отображают цифру в соответствующем знакоместе на 2.5 разрядном LCD от 0 до 199.
    Преобразование числа в BCD формат.
    Эта жесть даёт выигрыш порядка 10 мкА перед "обычным" преобразования с делениями на 10 за счёт меньшего времени работы CPU для расчёта. Вроде говнокод, но в данном случае оправдан, потому не воняет :)

    FlySnake, 09 Июля 2014

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

    +136

    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
    switch(event->touch_point) {
          case 5:
             input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
             input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x5);
             input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y5);
             input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
             input_mt_sync(data->input_dev);
    //         printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
          case 4:
             input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
             input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x4);
             input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y4);
             input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
             input_mt_sync(data->input_dev);
    //         printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
          case 3:
             input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
             input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x3);
             input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y3);
             input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
             input_mt_sync(data->input_dev);
    //         printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
          case 2:
             input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
             input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x2);
             input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y2);
             input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
             input_mt_sync(data->input_dev);
    //         printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
          case 1:
             input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
             input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x1);
             input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y1);
             input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
             input_mt_sync(data->input_dev);
             printk("===x1 = %d,y1 = %d ====\n",event->x1,event->y1);
    
          default:
    //         printk("==touch_point default =\n");
             break;
       }

    Автору платили за строки?
    Из драйвера тачскрина ft5x0x

    Pythoner, 28 Июня 2014

    Комментарии (28)
  7. Си / Говнокод #16222

    +136

    1. 1
    else if ( (ucmd->upmove > 10) && (self->client->ps.pm_flags & PMF_JUMP_HELD) && self->client->ps.groundTime && (level.time - self->client->ps.groundTime) > 150 && !BG_HasYsalamiri(g_gametype.integer, &self->client->ps) && BG_CanUseFPNow(g_gametype.integer, &self->client->ps, level.time, FP_LEVITATION) )

    Нам нужно больше условий!

    gost, 24 Июня 2014

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

    +136

    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
    static string[] ArrayFuller(string pathToFile)
            {
    
                int rr = 0;
                StreamReader sr=new StreamReader(pathToFile);
                while(!sr.EndOfStream){
                sr.ReadLine();
                rr++;
                }
                StreamReader sr2 = new StreamReader(pathToFile);
                string[] arrayBox = new string[rr];
                for (int i = 0; i < rr; i++)
                {
                    arrayBox[i] = Convert.ToString(sr2.ReadLine());
                }
                sr2.Close();
                return arrayBox;
            }

    vladb9582, 18 Июня 2014

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

    +136

    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
    // Playground - noun: a place where people can play
    
    import Cocoa
    
    // Изначальный массив и ссылка на него
    var originalArray: Int[] = [1, 2, 3];   // [1, 2, 3]
    var extraArray = originalArray          // [1, 2, 3]
    
    // Поменяем во втором массиве элемент
    extraArray[0] = 666
    
    // Оппа изменился и в первом
    extraArray                              // [666, 2, 3]
    originalArray                           // [666, 2, 3] O_o
    
    // Не делись!
    extraArray.unshare()
    
    // Теперь они живут своей жизнью
    extraArray[0] = 333
    
    extraArray                              // [333, 2, 3] okay
    originalArray                           // [666, 2, 3]
    
    // А вот тут будет наоборот
    var anotherArray = originalArray        // [666, 2, 3]
    
    // auto unshare
    anotherArray.append(-1)
    anotherArray.removeLast()
    
    anotherArray[0] = 777
    
    anotherArray                            // [777, 2, 3]
    originalArray                           // [666, 2, 3]
    
    // Словари вообще не так себя ведут, всегда копирование
    
    var originalDictionary = [ 1: "hello", 2: "world"]
    var extraDictionary = originalDictionary
    extraDictionary[1] = "no way"
    
    originalDictionary      // [ 1: "hello", 2: "world"]
    extraDictionary         // [ 1: "no way", 2: "world"]

    Я восхвалял Свифт, а же его и обосру.
    В Свифте есть массивы и словари. Так вот словари при присваивании или передаче как аргумента копируются. Окей. Теперь массивы. Они, оказывается, не копируются, а разделяют значения между собой! Т. е. передал массив в ф-цию, она там что-то испортила, массив испортился везде, где засветился.
    Чтобы эту фигню остановить, нужно вызывать спец. функцию unshare
    Но это еще не все. При некоторых операциях с массивами (потенциально меняющих их длину) unshare делается автоматически!

    Предвижу классическую ошибку свифтокодеров: ожидал, что массив поменяется, а он не поменялся снаружи; или передал массив, поюзал, а он снаружи неожиданно испортился. Плюс путаница, что базовые типы ведут себя по-разному.
    Оправдание Apple: мы хотели перформанс С-массивов в Свифте, поэтому сделали эту хрень.

    tirinox, 04 Июня 2014

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

    +136

    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
    // Определить тип ОС
       string OSVersion = null;
       try
       {
        try
        {
         OSVersion = Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\", "ProductName", "").ToString();
        }
    
        catch (NullReferenceException)
        {
        OSVersion = "";
        }
       }
       
       catch (SecurityException)
       {
        OSVersion = "";
       }
    
       finally {} // иначе при вложенном try ошибка

    Говницо собственного производства, когда учился программировать на первой работе.

    Smekalisty, 27 Мая 2014

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

    +136

    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
    SqlConnection con = new SqlConnection(connectionString);
                string sql = "SELECT idea.Id, idea.Small_text, idea.Full_text, idea.Example_text, ";
                sql = sql + " ul.FullName as Avtor, ref.Name as Status, even.date_act, (select count (*) from events ev where ev.id_action=2 and ev.id_target=idea.Id and ev.type_target=1) as CountComm, (select count (*) from events ev where ev.id_action=57 and ev.id_target=idea.Id and ev.type_target=1) as Voit, (select max(ev.date_act) from events ev where ev.id_action in (1,2,4,5,7,8,9,10,58,60,61,62,63,64,65,66,67,68,69,70,71,72,74) and ev.id_target=idea.Id and ev.type_target=1) as Last_action";
                sql = sql + " FROM Idea idea, UserLists ul, Refbook ref, Events even ";
                sql = sql + " WHERE idea.Avtor=ul.Id and idea.Status_id = ref.Id and even.id_action=1 and even.type_target=1 and even.id_target=idea.id ";
                if (id >= 0)
                    sql = sql + "  and idea.Status_id=" + id;
                if (id_avtor >= 0)
                    sql = sql + "  and idea.Avtor=" + id_avtor;
                sql = sql + " ORDER BY Last_action desc";
    
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.CommandType = CommandType.Text;
                List<Idea> Ideas = new List<Idea>();
                using (con)
                {
                    con.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Idea idea = GetIdeaInfo(Int32.Parse(reader["Id"].ToString()));
                        Ideas.Add(idea);
                    }
                    reader.Close();
                    return Ideas;
                }

    Принял еще один проект. ASP.NET MVC4. Автор уехал в Новую Зеландию.

    Vince, 28 Апреля 2014

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