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

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

    +12

    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
    struct c_test
    {
      int value;
      
      c_test(void)
      {
        (void)new (this) c_test (10);
      }
      
      c_test(int v)
      {
        value = v;
      }
    };

    LispGovno, 26 Июля 2013

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

    +132

    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
    #define max    0x08         //Max number of samples to average/filter
    #define byte unsigned char
    #define word unsigned int
    #define dword unsigned long
    
    #define FILTER 0
    #define AVG 1
    
    typedef struct  {
      word  reading[max];
      word  result[max];
    } ResultStct;
    
    
    static ResultStct x;
    static char samp = 0;//filter;
    const byte filter_mode = FILTER;
    
    extern int avg_result;
    
    void MYfilter(word input_sample) 
    {
      byte j;
      dword X;
        
    	x.reading[samp] = input_sample;
      
    	if(samp>0){
    
    		X=0;
    		for (j=0;j<=samp;j++){
    		  X += x.reading[j];
    		}
    		avg_result = (X >> 3) - 0x0200;
    		
    	} 
       
    	// Shift array of results if we hit max
    	if (samp >= max-1) {
    		for (j=0;j<max-1;j++){
    			x.result[j]  = x.result[j+1];
    			x.reading[j] = x.reading[j+1];
    		}
    		samp = max-1;
    	}
    	else 
    	{
    		samp++;
    	} //end if (i => max)

    Такой вот МОЩНЕЙШИЙ фильтр встретился в одном проекте.

    _113, 24 Июля 2013

    Комментарии (18)
  4. Objective C / Говнокод #13464

    −101

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    @implementation NSString (toint)
    - (long long)toInt {
        if (self == nil) return 0;
        if (self.length == 0) return 0;
       return [self longLongValue];
    }
    @end

    В этом коде все прекрасно. Я просто оставлю это здесь. Джава головного мозга.

    notxcain, 22 Июля 2013

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

    +7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    namespace engine { namespace ui { class Console; } }
    
    class Dummy
    {
       engine::ui::Console * _ptr;
    };

    Решение проблемы с перекрёстными #include, когда классы должны хранить указатели друг на друга. Простое объявление class engine::ui::Console; не работает.
    Не в первый раз сталкиваюсь с этой проблемой из-за примитивной системы импорта.

    an0nym, 20 Июля 2013

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

    +138

    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
    uint32_t multiply (uint16_t a, uint16_t b)
    {
      return ((a &  ( (int16_t)( ( b & (1 << 0) ) << 15 ) ) / ( 1 << 15) ) << 0 ) +
             ((a &  ( (int16_t)( ( b & (1 << 1) ) << 14 ) ) / ( 1 << 15) ) << 1 ) +
             ((a &  ( (int16_t)( ( b & (1 << 2) ) << 13 ) ) / ( 1 << 15) ) << 2 ) +
             ((a &  ( (int16_t)( ( b & (1 << 3) ) << 12 ) ) / ( 1 << 15) ) << 3 ) +
             ((a &  ( (int16_t)( ( b & (1 << 4) ) << 11 ) ) / ( 1 << 15) ) << 4 ) +
             ((a &  ( (int16_t)( ( b & (1 << 5) ) << 10 ) ) / ( 1 << 15) ) << 5 ) +
             ((a &  ( (int16_t)( ( b & (1 << 6) ) << 9  ) ) / ( 1 << 15) ) << 6 ) +
             ((a &  ( (int16_t)( ( b & (1 << 7) ) << 8  ) ) / ( 1 << 15) ) << 7 ) +
             ((a &  ( (int16_t)( ( b & (1 << 8) ) << 7  ) ) / ( 1 << 15) ) << 8 ) +
             ((a &  ( (int16_t)( ( b & (1 << 9) ) << 6  ) ) / ( 1 << 15) ) << 9 ) +
             ((a &  ( (int16_t)( ( b & (1 <<10) ) << 5  ) ) / ( 1 << 15) ) << 10) +
             ((a &  ( (int16_t)( ( b & (1 <<11) ) << 4  ) ) / ( 1 << 15) ) << 11) +
             ((a &  ( (int16_t)( ( b & (1 <<12) ) << 3  ) ) / ( 1 << 15) ) << 12) +
             ((a &  ( (int16_t)( ( b & (1 <<13) ) << 2  ) ) / ( 1 << 15) ) << 13) +
             ((a &  ( (int16_t)( ( b & (1 <<14) ) << 1  ) ) / ( 1 << 15) ) << 14) +
             ((a &  ( (int16_t)( ( b & (1 <<15) ) << 0  ) ) / ( 1 << 15) ) << 15);
    }

    Умножение двух чисел через битовые маски и сдвиги без условных переходов. Компилятор переведет деление инта на сдвинутую единчку в арифметический сдвиг
    Использование ">>" применительно к signed типам - implementation defined http://stackoverflow.com/questions/4009885/arithmetic-bit-shift-on-a-signed-integer/4009922

    j123123, 18 Июля 2013

    Комментарии (18)
  7. Pascal / Говнокод #13412

    +86

    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
    96. 96
    procedure TForm1.Colorize;
    procedure SetStr(var s: string; const Style: TFontStyles; const Color, BackColor: Byte);
    var
      Format: TCharFormat2;
    begin
     If s<>'' Then
      begin
        FillChar(Format, SizeOf(Format), 0);
        Format.cbSize := SizeOf(Format);
        Format.dwMask:= CFM_BACKCOLOR or CFM_COLOR;
        Format.crBackColor:= GetIRCColor(BackColor, True);
        Format.crTextColor:= GetIRCColor(Color);
        if RichEdit1.HandleAllocated then
        SendMessage(RichEdit1.Handle, EM_SETCHARFORMAT, SCF_SELECTION,
          LPARAM(@Format));
        RichEdit1.SelAttributes.Style:= Style;
        RichEdit1.SelText:= s;
        RichEdit1.SelAttributes.Assign(RichEdit1.DefAttributes);
        s:= ''
      end;
    end;
    var
      Color, BackColor: Byte;
      Style: TFontStyles;
      CurrStr: string;
      I: Integer;
    begin
      Style:= [];
      Color:= DefForeColor;
      BackColor:= DefBackColor;
      CurrStr:= '';
      I:= 0;
      While (I<Length(Str))do
       begin
        Inc(I);
        case Str[I] of
          #31:
              begin
               SetStr(CurrStr, Style, Color, BackColor);
               If fsUnderLine in Style Then
                Exclude(Style, fsUnderLine)
               else
                Include(Style, fsUnderLine);
             end;
          #2:
             begin
               SetStr(CurrStr, Style, Color, BackColor);
               If fsBold in Style Then
                Exclude(Style, fsBold)
               else
                Include(Style, fsBold);
             end;
           #15, #13:
               begin
                SetStr(CurrStr, Style, Color, BackColor);
                Color:= DefForeColor;
                BackColor:= DefBackColor;
               end;
           #3:
              begin
                SetStr(CurrStr, Style, Color, BackColor);
                Inc(I);
                Color:= DefForeColor;
                If (Str[I] in ['0', '1'..'9'])Then
                 begin
                  Color:= StrToInt(Str[I]);
                  Inc(I);
                  If (Str[I] in ['0', '1'..'9'])Then
                   begin
                     Color:= StrToInt(IntToStr(Color)+Str[I]);
                     Inc(I)
                   end;
                 end;
                 If Str[I] = ',' Then                         //BackColor
                   begin
                    BackColor:= DefBackColor;
                    Inc(I);
                    If (Str[I] in ['0', '1'..'9'])Then
                     begin
                      BackColor:= StrToInt(Str[I]);
                      Inc(I);
                      If (Str[I] in ['0', '1'..'9'])Then
                       begin
                        BackColor:= StrToInt(IntToStr(BackColor)+Str[I]);
                        Inc(I)
                       end;
                      end;
                    end;
                   Dec(I) 
              end;
           else
            CurrStr:= CurrStr+Str[I]
        end;
       end;
       SetStr(CurrStr, Style, Color, BackColor);
    end;

    Процедура раскрашивающая текст из Log-файла mIRC загруженого в TRichEdit на форме.

    function GetIRCColor(const Color: Byte; const Back: Boolean=False): TColor;
    begin
    case Color of
    0: Result:= clWhite;
    1: Result:= clBlack;
    2: Result:= clNavy;
    3: Result:= clGreen;
    4: Result:= clRed;
    5: Result:= clMaroon;
    6: Result:= clPurple;
    7: Result:= $000080FF;
    8: Result:= clYellow;
    9: Result:= clLime;
    10: Result:= clTeal;
    11: Result:= clAqua;
    12: Result:= clBlue;
    13: Result:= clFuchsia;
    14: Result:= clGray;
    15: Result:= clSilver;
    else
    begin
    If Back Then
    Result:= clWhite
    else
    Result:= clBlack
    end;
    end;
    end;

    ASNightingale, 12 Июля 2013

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    extract($params);
            foreach (array("subject", "title", "content") as $par) {
                if (empty($$par)) {
                    return false;
                }
            }

    Валидация входных параметров. Каждая строка тут прекрасна

    quall, 10 Июля 2013

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

    +130

    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
    public object Clone()
    {
    	using (MemoryStream stream = new MemoryStream())
    	{
    		BinaryFormatter formatter = new BinaryFormatter();
    		formatter.Serialize(stream, this);
    		stream.Position = 0;
    		ColLink result = (ColLink)formatter.Deserialize(stream);
    		result.Id = IdentityManager.GetId();
    		result.GUID = Guid.NewGuid();
    		result.setEdited();
    		result.setCreated();
    		return result;
    	}
    }

    Клонирование

    dormendo, 04 Июля 2013

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

    +105

    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
    private void timer1_Tick(object sender, EventArgs e)
            {
                sec++;
    
                if (sec > 59)
                {
                    min++;
                    if (min > 59)
                    {
                        ch++;
                        min = 0;
                    }
                    sec = 0;
                }
    
                label1.Text = "Время игры: \r\n" + ch + ":" + min + ":" + sec;
            }

    Часики -_-

    ipro, 12 Июня 2013

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

    +114

    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
    #include <stdio.h>
         
        int main() {
            int i=5;
            switch ( 2 ) {
                case 0:
                    for (  i=0; i<10; i++ ) {
                case 1:
                    printf("A i=%d\n",i);
                case 2:
                    printf("B i*i=%d\n",i*i);
                    };
                case 3:
                    printf("done");
                    break;
            }
         
            return 0;
        }
         
        /* OUTPUT
        B i*i=25
        A i=6
        B i*i=36
        A i=7
        B i*i=49
        A i=8
        B i*i=64
        A i=9
        B i*i=81
        done
        */

    http://pastebin.com/EY3WQNzC - казехак.

    serpinski, 06 Июня 2013

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