1. C++ / Говнокод #17964

    +137

    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
    #include <iostream>
    
    template <typename T>
    struct Symbol {};
    
    template <>
    struct Symbol<int> {
        static constexpr const char value = 'd';
    };
    template <>
    struct Symbol<float> {
        static constexpr const char value = 'f';
    };
    
    template<std::size_t N, typename T>
    constexpr bool check_arg_part(const char (&s)[N], size_t i, T d)
    {
        if (i == N)
            return true;
    
        if (i < N - 1) {
            if (s[i] == '%') {
                if (s[i + 1] != Symbol<T>::value)
                    return false;
            }
        }
        return check_arg_part(s, i + 1, d);
    }
    
    template<std::size_t N, typename T>
    constexpr bool check_arg(const char (&s)[N], T d) {
        return check_arg_part(s, 0, d);
    }
    
    int main(int , char*[]) {
        std::boolalpha(std::cout);
    
    
        constexpr bool r = check_arg("foo is int: %d", 1);
        std::cout << "Argument integer is correct: " << r << std::endl;
        constexpr bool r1 = check_arg("foo is float:  %f", 1.0f);
        std::cout << "Argument float is correct: " << r1 << std::endl;
        constexpr bool r2 = check_arg("foo is float: %f", 1);
        std::cout << "Argument int is correct: " << r2 << std::endl;
    
        return 0;
    }

    По мотивам http://govnokod.ru/17925:

    Функция в compile time проверяет соответствие типов. Работает на clang и почему-то валится на gcc.

    gorthauer87, 09 Апреля 2015

    Комментарии (10)
  2. Python / Говнокод #17963

    −88

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    С сайта http://www.codecademy.com/
    
    Dot Notation
    Let's take a closer look at why you use len(string) and str(object), but dot notation (such as "String".upper()) for the rest.
    
    lion = "roar"
    len(lion)
    lion.upper()
    
    Methods that use dot notation only work with strings.
    
    On the other hand, len() and str() can work on other data types.

    То ли лыжи не едут, то ли я ебанутый.

    kegdan, 09 Апреля 2015

    Комментарии (54)
  3. Python / Говнокод #17962

    −115

    1. 1
    print 1 < 2 == 2 > 1 in [1,2,3] < [2,3,4,5] != 1

    Данный кусочек кода ( взял на одном из сайтов с тестами) навел меня на мысль - а может быть люди говнокодят потому, что языки программирования позволяют это делать? Взглянув на него первая моя мысль была - что это за хрень, она не будет работать. Оказалось я был не прав.

    Zuzik, 08 Апреля 2015

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

    +125

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    Bool_vector::operator«(int) // сдвиг
    {
    int i;
    for (i=0;i<this->n;i++)
    cout»(*this)[i];
    }

    Человек далёк от программирования.
    Пытается написать лабу.
    Не блондинко.
    Я при виде этого не сдержался.

    mittorn, 08 Апреля 2015

    Комментарии (29)
  5. 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)
  6. PHP / Говнокод #17959

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public function searchPaymentsByParams($timestampFrom=null, $timestampTo=null, $recipient=null, $client_id=null,
    										   $pay_system=null, $account=null, $ip=null, $status=null,
    										   $pay_currency=null, $pay_amount_from=null, $pay_amount_to=null,
    										   $get_currency=null, $get_amount_from=null, $get_amount_to=null,
    										   $status_ps=null, $limit=30, $offset=0);

    проект сосотоит чуть менее чем полностью из подобных сигнатур

    vetaswind, 08 Апреля 2015

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

    +134

    1. 1
    static_cast<Vampire*>(&attacker)->suckHpFrom(attacked, damage * Vampire::hpSuckRatio);

    artembegood, 08 Апреля 2015

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

    +143

    1. 1
    for (val side: new boolean[] { false, true }) {

    someone, 08 Апреля 2015

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

    +101

    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
    94. 94
    95. 95
    var
      Excel: OleVariant;
      Rows, Cols: integer;
      WorkSheet: OleVariant;
      DebugList: TStringList;
      I, j, CSeek: integer;
      R, ArrV: OleVariant;
      ObjData: TDataContainer;
      D: integer;
    begin
     {$IFDEF DEBUG}
      DebugList := TStringList.Create;
     {$ENDIF}
      try
        Excel := CreateOleObject('Excel.Application');
        Excel.Visible := false;
        Excel.Workbooks.Open[DocPath, 0, True];
        WorkSheet := Excel.ActiveWorkbook.ActiveSheet;
        R := Excel.Intersect(WorkSheet.UsedRange,
          WorkSheet.UsedRange.Offset[14, 0]);
        ArrV := R.Value;
        Rows := VarArrayHighBound(ArrV, 1);
        Cols := VarArrayHighBound(ArrV, 2);
        {$IFDEF DEBUG}
        DebugList.Add(Format('Количество ячеек в таблице = %d', [(Rows) * Cols]));
        DebugList.Add(Format('Rows = %d, Cols = %d', [Rows, Cols]));
        {$ENDIF}
        CSeek := 0;
        D := 1;
        for I := 1 to Rows do
        begin
          if (CompareStr(Trim(VarToStr(ArrV[I, 1])), Trim('Итого')) = 0) then
            Break;
          if (CompareStr(Trim(VarToStr(ArrV[I, 1])),
            Trim('отдел')) = 0) or
            (CompareStr(Trim(VarToStr(ArrV[I, 1])), Trim('10.05')) = 0) or
            (CompareStr(Trim(VarToStr(ArrV[I, 1])), Trim('10.06')) = 0) or
            (CompareStr(Trim(VarToStr(ArrV[I, 1])), Trim('10.09')) = 0) then
          begin
            CSeek := I + 2;
            Continue;
          end;
          if CSeek > I then
            Continue;
          for j := 1 to Cols do
          begin
            case j of
              1:
                begin
                  if VarToStr(ArrV[I, j]) <> '' then
                  begin
                    ObjData := TDataContainer.Create;
                    ObjData.Name := ArrV[I, j];
                  end;
                end;
              3:
                begin
                  if VarToStr(ArrV[I, j]) <> '' then
                    ObjData.InventoryNumber := GetInventoryNumber(ArrV[I, j]);
                end;
              10:
                begin
                  if (D mod 2 <> 0) then
                  begin
                    if VarToStr(ArrV[I, j]) <> '' then
                      ObjData.DataCount := ArrV[I, j];
                  end
                  else
                    ObjData.Cost := ArrV[I, j];
     
                  if (ObjData <> nil) and (ObjData.DataCount > 0) then
                  begin
                    FData.Add(ObjData);
                    DebugList.Add(ObjData.AsString);
                  end;
                end;
            end;
            Inc(D);
          end;
        end;
        {$IFDEF DEBUG}
        DebugList.Add('Objects created: ' + IntToStr(FData.Count));
        D:=1;
        for ObjData in FData.Items.Values do
           D := D + ObjData.DataCount;
        DebugList.Add('Total objects count: ' + IntToStr(D));
        DebugList.SaveToFile('C:\ExcelDebug.txt');
        {$ENDIF}
      finally
        {$IFDEF DEBUG}
        DebugList.Free;
        {$ENDIF}
        Excel.Quit;
      end;
    end;

    При разборе выхлопа из 1С в Excel - excel и формат выгрузки сделали всё, чтобы я люто наговнокодил-(

    Cynicrus, 08 Апреля 2015

    Комментарии (4)
  10. PHP / Говнокод #17955

    +137

    1. 1
    2. 2
    $path = substr(array_pop(array_reverse(explode("?", $_SERVER["REQUEST_URI"]))), 1);
    $text = urldecode(array_pop(explode("/", trim(array_pop(array_reverse(explode("?", str_replace(".png", "", $path))))))));

    Имеется скрипт, генерирующий изображение, с адресом типа "/images/4601546083333.png?height=420&width=1510" .
    В скрипте необходимо получить название запрошенного файла без расширения.

    jbot, 08 Апреля 2015

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