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

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

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    string fileName = Path.GetFileName(f);
    string fileExt = Path.GetExtension(f);
    string i=fileName.IndexOf(fileExt);
    if (i > -1) fileName = fileName.Remove(i, fileExt.Length);

    Получение имени файла

    sbs, 25 Декабря 2013

    Комментарии (12)
  3. JavaScript / Говнокод #14277

    +157

    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
    function currSnowCalcPrice(type, square, height){
                var price = false;
                switch (type) {
                  //скатная крыша
                  case 1:
                    switch (true) {
                      case square < 125:
                        price = 'min';
                      break      
                     //0 - 20см 
                      case height < 20:
                            switch (true) {                          
                              case square < 500:
                                    price = 39;
                                break
                              case square < 1000:
                                    price = 34;
                                break
                              case square < 2000:
                                    price = 32;
                                break                            
                              default:
                                price = 0;
                            }
                        break
                      //20 - 30 см  
                      case height < 30:
                            switch (true) {
                              case square < 500:
                                    price = 44;
                                break                        
                              default:
                                price = 39;
                            }
                        break
                      default:
                        price = 0;
                    }
                    break
                  case 2:
                    switch (true) {
                      case square < 250:
                        price = 'min';
                      break                     
                      //0 - 14см   
                      case height < 14:
                            switch (true) {
                              case square < 500:
                                    price = 21.5;
                                break  
                              case square < 4500:
                                    price = 19.5;
                                break  
                              case square < 9500:
                                    price = 17.5;
                                break  
                              case square < 15000:
                                    price = 15.5;
                                break                          
                              default:
                                price = 0;
                            }
                        break
                      //14 - 30 см  
                      case height < 30:
                            switch (true) {
                              case square < 500:
                                    price = 23.5;
                                break  
                              case square < 4500:
                                    price = 21.5;
                                break  
                              case square < 9500:
                                    price = 19.5;
                                break  
                              case square < 15000:
                                    price = 17.5;
                                break                          
                              default:
                                price = 0;
                            }
                        break
                      default:
                        price = 0;
                    }
                    break
                  default:
                    price = false;
                }
                return price;
            }

    Функция возвращает цену за уборку одного метра квадратного поверхности. Есть минимальное количество когда будет возвращено значение min. false или 0 в случае не существующего типа поверхности или значений площади или глубины вне загаданного диапазона.

    AlexP, 25 Декабря 2013

    Комментарии (12)
  4. JavaScript / Говнокод #14268

    +159

    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
    var a, vr, curq;
    function bgbuild(num1){document.write("<head><title>Річне тематичне оцінювання з астрономії</title><meta http-equiv=\"Content-Type\" content=\"text/html\" charset=unicode\"></head><body bgcolor=#8080ff><img src='library/bgrnd.jpg' height=100% width=100% style='z-index:",num1,";position:absolute;top:0;left:0;right:0;bottom:0'>")};
    function fio(){document.write("<form><input type=\"text\" name=\"pib\" style='z-index:4;position:relative;top:0;left:0;font:normal 15px Lucida Console;'>")};
    function capt(qustn){document.write("<div style='z-index:3;text-align:justify;position:absolute;top:30;left:30;font:normal 30px System;color:black'>",qustn,"</div>")};
    function fld(){document.write("<textarea name=answ rows=30 cols=90 style='z-index:4;position:absolute;top:160;left:30;font:normal 15px Lucida Console;'></textarea>")};
    function kg(qst){document.write("<input style=\"z-index:6;position:absolute;top:0;right:0\" type=\"button\" value=\"Наступне питання\" onclick=\"return q",qst,"()\">")};
    function registr(){document.write("<input type=\"button\" onclick=\"return crfol()\" value=\"Реєстрація\"></form>")};
    function cnctscr(){document.write("<script lang=\"Javascript\" src=\"library/cobuild.js\"></script>");};
    function svr(vr){var fs, b;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    b = fs.OpenTextFile("C:\\variant.tmp", 2, true, true);
    b.write(vr);
    b.close();
    };
    function gvr(){var fs, b;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    b = fs.OpenTextFile("C:\\variant.tmp", 1, true, true);
    vr = b.readall();
    b.close();
    };
    function start(){
    bgbuild(0);
    document.write("<div style='z-index:1;position:absolute;top:30;left:30;right:30;font:normal 25px System;color:black;text-align:justify'>Ви маєте можливість пройти річне тематичне оцінювання з астрономії. Буде запропоновано 6 варіантів по 15 питань різної складності кожний. Ваші відповіді перевіряє вчитель, але приблизно оцінити себе Ви можете самі, ознайомившись після проходження опитування із правильною відповіддю і оцінивши вірність своєї відповіді. Не намагайтесь втрутитись у хід опитування і підкорегувати свої відповіді, адже це може скінчитися порушенням ходу програми, яке призведе до її неповного проходження, а в результаті - нижчої оцінки. Файл із Вашою відповіддю збережеться у спеціальному місці.<br>Для початку введіть своє прізвище та ім'я (не використовуйте ніяких спецсимволів!):<br>");
    fio();
    registr();
    document.write("<br>Оберіть варіант:<br><table><tr><td><form><input type='button' value='1' onclick='svr(1);return q1()'></td><td><input type='button' onclick='svr(2);return q1()' value='2'></td><td><input type='button' onclick='svr(3);return q1()' value='3'></td><td><input type='button' onclick='svr(4);return q1()' value='4'></td><td><input type='button' onclick='svr(5);return q1()' value='5'></td><td><input type='button' onclick='svr(6);return q1()' value='6'></td></form></div>");};
    function crfol(){var fs, n, b;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    n = document.all.pib.value;
    if(n==""){er()};
    nm = "answ/"+n+".dat";
    a = fs.OpenTextFile(nm, 2, true, true);
    a.writeline("Це не підробка, це справжній файл із відповідями!\rУчень: "+n+"\rВаріант: ");
    a.close();
    b = fs.OpenTextFile("C:\\username.tmp", 2, true, true);
    b.write(n);
    b.close();
    }
    function crf(dt){var fs, n, b, nm;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    b = fs.OpenTextFile("C:\\username.tmp", 1, true, true);
    n = b.readall();
    b.close();
    nm = "answ/"+n+".dat";
    a = fs.OpenTextFile(nm, 8, true, true);
    a.writeline(dt);
    a.close();
    }
    function er(){alert("Ану не балуйся! Думаєш, ти розумніше за комп'ютер?!");window.close();}
    function q1(){
    try{
    gvr();
    crf(vr);
    bgbuild(0);
    cnctscr();
    };catch(e){er()};
    if (vr=="1"){curq = "1.1.1. Що вивчає астрономія?"};
    if (vr=="2"){curq = "1.1.2. Що означає слово \"астрономія\"?"};
    if (vr=="3"){curq = "1.1.9. Що таке астрологія?"};
    if (vr=="4"){curq = "1.1.12. Назвіть прізвища відомих вам астрономів минулих часів."};
    if (vr=="5"){curq = "1.1.13. Назвіть небесні тіла, що утворюють Сонячну систему."};
    if (vr=="6"){curq = "2.1.1. Що означає слово \"космос\"?"};
    capt(curq);
    crf(curq);
    fld();
    
    kg(2);
    }
    
    start();

    Короче, первый мой более-менее крупный высер на JS. Писал HTA-приложение для школы (тестирование по астрономии). Интернета у меня тогда ещё не было, компилятор чего-либо нормального взять, соответственно, было негде, поэтому писал на чём можно. JS (точнее, JScript) изучал по справке MSE7 (недо-IDE, которая поставляется с M$Office). Результат немного предсказуем, многие части кода - модифицированные примеры тамошние. Вбрасываю основную либу (там ещё дополнительная, с вхардкоженными вопросами и несколькими функциями, и HTA-оболочка). Остальное будет по просьбам:3

    //Я в этот код даже не заглядываю, боюсь суицидальных приступов от осознания того, что я это написал *HEADBANG*

    MiniRoboDancer, 24 Декабря 2013

    Комментарии (12)
  5. PHP / Говнокод #14240

    +119

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    Well, there were other factors in play there. htmlspecialchars was a
    very early function. Back when PHP had less than 100 functions and the
    function hashing mechanism was strlen(). In order to get a nice hash
    distribution of function names across the various function name lengths
    names were picked specifically to make them fit into a specific length
    bucket. This was circa late 1994 when PHP was a tool just for my own
    personal use and I wasn't too worried about not being able to remember
    the few function names.
    
    -Rasmus

    http://news.php.net/php.internals/70691

    someone, 17 Декабря 2013

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

    +78

    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
    private int compareDates(java.sql.Date date1, java.sql.Date date2) {
    
    if (date1.getYear() < date2.getYear())
    return 1;
    
    if (date1.getYear() > date2.getYear())
    return -1;
     
    if (date1.getMonth() < date2.getMonth())
    return 1;
    
    if (date1.getMonth() > date2.getMonth())
    return -1;
     
    if (date1.getDate() < date2.getDate())
    return 1;
    
    if (date1.getDate() > date2.getDate())
    return -1;
     
    return 0;
    }

    Сравнение двух дат

    iboken, 10 Декабря 2013

    Комментарии (12)
  7. PHP / Говнокод #14185

    +159

    1. 1
    $safedatasry = str_replace ('', '', $safedatasry);

    psycho-coder, 06 Декабря 2013

    Комментарии (12)
  8. Куча / Говнокод #14181

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video {
        margin:0;
        padding:0;
        border:0;
        font-size:1em;
        font-family:'Helvetica','Arial',sans-serif;
        vertical-align:baseline
    }

    invision70, 05 Декабря 2013

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

    +64

    1. 1
    2. 2
    Я МОГ БЫ НАКАЛДАВАТЬ СИБЕ ЛАЙКАВ НО МНЕ ЗАПРИЩИНО ИСПОЛЬЗЫВАТЬ МАГИЮ ВНЕ ХОГВАРЦА
    НО ВАЛШЕБНАЯ ПАЛАЧКА У МИНЯ ЕСТЬ МОЖЫШЬ У СВАЕЙ МАМКИ СПРАСИТЬ ЕСЛЕ НЕ ВЕРИЖ АЗАЗАЗАЗЗАЗЗЗЗААА)))00))00)0000

    ЭКСПЕРТУС ТРАЛИУС АЗАЗА))0)0

    PragramistOtBoga, 20 Октября 2013

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

    +139

    1. 1
    out[0] = str[0] > str[1] && str[0] > str[2] ? (out[1] = str[1] > str[2] ? (out[2] = str[2],str[1]) : (out[2] = str[1],str[2]) ,str[0]) : (str[1] > str[2] ? (out[1] = str[0] > str[2] ? (out[2] = str[2],str[0]): (out[2] = str[0],str[2]),str[1]) :(out[1] = str[0] > str[1] ? (out[2] = str[1],str[0]): (out[2] = str[0],str[1]),str[2]) );

    Сортируем 3 символа.

    Abbath, 16 Октября 2013

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

    +128

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (null != this.messageTemplateResourceName && null != this.messageTemplateResourceType)
    {
        return ResourceStringLoader.LoadString(this.messageTemplateResourceType.FullName,
            this.messageTemplateResourceName,
            this.messageTemplateResourceType.Assembly);
    }
    if (null != this.messageTemplateResourceName || null != this.messageTemplateResourceType)
    {
        throw new InvalidOperationException(Resources.ExceptionPartiallyDefinedResourceForMessageTemplate);
    }

    Microsoft EnterpriseLibrary
    else? нет, не слышал

    NeoN, 29 Августа 2013

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