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

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

    +133

    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
    if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("");
    else if (textBox[0].Text != "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%'", textBox[0].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%'", textBox[1].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%'", textBox[2].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("course={0}", textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("group={0}", textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%'", textBox[0].Text, textBox[1].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%'", textBox[1].Text, textBox[2].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%' and course={1}", textBox[2].Text, textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("course={0} and group={1}", textBox[3].Text, textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%'", textBox[0].Text, textBox[1].Text, textBox[2].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%' and course={2}", textBox[1].Text, textBox[2].Text, textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%' and course={1} and group={2}", textBox[2].Text, textBox[3].Text, textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%' and course={3}", textBox[0].Text, textBox[1].Text, textBox[2].Text, textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%' and course={2} and group={3}", textBox[1].Text, textBox[2].Text, textBox[3].Text, textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%' and course={3} and group={4}", textBox[0].Text, textBox[1].Text, textBox[2].Text, textBox[3].Text, textBox[4].Text);

    "Есть 5 текстовых полей и желание понять, как можно в зависимости от пустоты или заполненности этих полей, одного или нескольких создать малое количество операторов if else"

    Порадовало "малое количество"

    Psilon, 08 Апреля 2015

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

    +133

    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
    int start()
      {
     string filename = "GBPJPY.hst";
     int i_unused[30];
       
     int FILE = FileOpenHistory(filename, FILE_READ|FILE_BIN);
     FileSeek(FILE, 0, SEEK_SET);
     
     int version    = FileReadInteger (FILE, LONG_VALUE);
     string c_copyright  = FileReadString (FILE, 64);
     string name    = FileReadString (FILE, 12);
     int period     = FileReadInteger (FILE, LONG_VALUE);
     int i_digits   = FileReadInteger (FILE, LONG_VALUE);
     int timesign    = FileReadInteger (FILE, LONG_VALUE);       //timesign
     datetime last_sync   = FileReadInteger (FILE, LONG_VALUE);       //last_sync
     FileReadArray (FILE, i_unused, 0, 13);
     
     Print("Version = ", version);
     Print("c_copyright = ", c_copyright);
     Print("Equity = ", name);
     Print("period = ", period);
     Print("i_digits = ", i_digits);
     Print("timesign = ", TimeToStr(timesign, TIME_DATE|TIME_SECONDS));
     Print("last_sync = ", last_sync);
     Print("i_unused = ", i_unused[0]);
     Print("i_unused = ", i_unused[1]);
     Print("i_unused = ", i_unused[2]);
     Print("i_unused = ", i_unused[3]);
     Print("i_unused = ", i_unused[4]);
     Print("i_unused = ", i_unused[5]);
     Print("i_unused = ", i_unused[6]);
     Print("i_unused = ", i_unused[7]);
     Print("i_unused = ", i_unused[8]);
     Print("i_unused = ", i_unused[9]);
     Print("i_unused = ", i_unused[0]);
     Print("i_unused = ", i_unused[11]);
     Print("i_unused = ", i_unused[12]);
     Print("Time    = ", FileReadInteger (FILE, LONG_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Volume   = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Time    = ", FileReadInteger (FILE, LONG_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Volume   = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Time    = ", FileReadInteger (FILE, LONG_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Volume   = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Time    = ", FileReadInteger (FILE, LONG_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Price    = ", FileReadDouble (FILE, DOUBLE_VALUE));
     Print("Volume   = ", FileReadDouble (FILE, DOUBLE_VALUE));
     FileClose(FILE);   
     return(0);
    }

    Язык программирования торгового терминала MetaTrader 4 - MQL 4 - имеет C-нотацию. Многое роднит его с языком C, поэтому пример размещаю сюда.
    У меня складывается мнение, что, как и Forex - дно (днище) в мире электронной торговли, так и основная масса кода, написанного на MQL4 - образец того, как
    НЕ нужно программировать! Чего стоит одна только вырвиглазная разметка вкупе с корявым непоследовательным именованием... характерная, в том числе,
    и для официально поставляемых с терминалом примеров кода. Заранее прошу прощения за многострочный пример

    AndreySt, 02 Марта 2015

    Комментарии (31)
  4. Куча / Говнокод #17688

    +133

    1. 1
    2. 2
    HTTP referer (originally a misspelling of referrer) is an HTTP header field that identifies the address of the webpage
    (i.e. the URI or IRI) that linked to the resource being requested.

    Originally a misspelling of referrer...

    bormand, 24 Февраля 2015

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

    +133

    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
    public string GenerateWinCode(String PrefixWinCode, String Name, String LastName, String NameCompany, bool IsCompany = false)
            {
                string _NormalWinCode = "";
                if (!IsCompany)
                    _NormalWinCode = (PrefixWinCode + Name[0] + LastName[0]).ToUpper();
                else
                {
                    var i = 1;
                    try
                    {
                        while (String.IsNullOrWhiteSpace(NameCompany[i].ToString()))
                        {
                            i++;
                        }
                        _NormalWinCode = (PrefixWinCode + NameCompany[0] + NameCompany[i]).ToUpper();
                    }
                    catch (Exception)
                    {
                        _NormalWinCode = (PrefixWinCode + NameCompany[0] + NameCompany[0]).ToUpper();
                    }
                }
                if (PrefixWinCode == "IN")
                    throw new RuleException("ErrorWincode", Resources.Accounts.Account.WincodeInvalid);
                try
                {
                    using (var context = db)
                    {
                        var _WincodesSim =
                            (from q in context.UserPartners.Where(m => m.WinCode.ToUpper().StartsWith(_NormalWinCode))
                             where q.WinCode.Length > 4
                             select q.WinCode).ToList();
                        var _Sufix = _WincodesSim.Select(m => Convert.ToInt32(m.Substring(4))).Max();
                        return _NormalWinCode + (_Sufix + 1);
                    }
                }
                catch (InvalidOperationException)
                {
                    return _NormalWinCode + 1;
                }
            }

    Генерация уникальных ключей

    AndrewTakker, 24 Февраля 2015

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    int main(void)
    {
    	int a=0,b=1000;
    	int * p;
    	p=malloc(sizeof(int)*b-7); // уменьшаем выделяемую память на 7 байт, а почему оно не падает?
    	for(;a<b;a++) p[a]=a;
    	printf("%lu",sizeof(int)*b);
    	free(p);
    }

    а если убрать 8 байт то уже падает,что-то где-то округляется что-ли?

    pl7ofit, 10 Февраля 2015

    Комментарии (14)
  7. Куча / Говнокод #17599

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    STEAMROOT="$(cd "${0%/*}" && echo $PWD)")
    
    ...
     rm -rf "$STEAMROOT/"*

    http://www.opennet.ru/opennews/art.shtml?num=41469

    эпик фейл
    #юмор
    #идиоты

    Lure Of Chaos, 07 Февраля 2015

    Комментарии (20)
  8. PHP / Говнокод #17564

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /**
         * Verify displayed special product price on product page(front-end) equals passed from fixture.
         *
         * @return null|string|void
         */
        protected function verifySpecialPrice()
        {
            return null;
        }

    Судя с того, что написано в дескрипшене, а именно
    @return void
    даный метод можно свести к
    return;
    или даже
    //

    Lord723518, 03 Февраля 2015

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

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    #include <stdio.h>
    int main () {
    char c;
    int result=0;
    while(scanf("%c",&c) ) {
    if( (c<'0') || (c > '1') ) break;
    result«=1;
    result+=c-'0';
    };
    printf("%d",result);
    return 0;
    }

    Этот код переводит число из двоичной системы в десятичную. Зачем-то основано на работе с символами.

    alexmir, 29 Января 2015

    Комментарии (38)
  10. Куча / Говнокод #17535

    +133

    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
    // Common styles for any tag
    .clear {
      clear: both;
    }
    
    .grey {
      color: $pcolor;
    }
    
    .colored {
      color: $headercolor;
    }
    
    .siteName {
      font-family: $siteNameFontFamily;
    }
    
    .common-ctx {
      color: $pcolor;
      font-size: 105%;
    }
    .common-ctx-light {
      color: $pcolorlight;
      font-size: 100%;
    }
    
    .fs95 {
      font-size: 95%;
    }
    
    .undisplayable {
      display: none;
    }
    
    .displayable {
      display: block;
    }
    
    hr.black-hr {
        border-color: black;
        margin: 10px 0 10px 0;
    }
    
    hr.grey-hr {
        border-color: #cccccc;
        margin: 20px 0 30px 0;
    }
    
    .w30p {
      width: 30% !important;
    }
    
    .w100 {
      width: 100%;
    }
    
    .fl {
      float: left;
    }
    
    .p0 {
        padding: 0 !important;
    }

    Самые интуитивно-понятные имена CSS-классов.

    crazyh, 28 Января 2015

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

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    void	Nay_Prer_Timer2(void)
    {
      Obr_Func_Prer.Sh_Time2 = Obr_Func_Prer.Sh_Time2_Init;
      Spec_Vkl_Indic.Sh_Time2 = Spec_Vkl_Indic.Sh_Time2_Init;
      Spec_Vykl_Indic.Sh_Time2 = Spec_Vykl_Indic.Sh_Time2_Init;
      Flag_Morg=0;	// Флаг моргания для Config_Bibl_Max6954
      Flag_Vykl_Diod=0;
      if(Config_Bibl_Max6954&0x4)	// 2-й бит =1 - Прерывания разрешены
        Vkl_Prer_Timer2();
      return;
    }

    Чел писал тестовое задание для микроконтроллера (поморгать светодиодами).
    На вопрос что означает слово Nay в названии функции был дан ответ - это сокращение от нач. (начало).

    synya, 23 Января 2015

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