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

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

    +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
    48. 48
    49. 49
    50. 50
    model.PID = row["PID"].ToString();
    model.Rect = row["RECt"].ToString();
    model.Pubt = row["PUBt"].ToString();
    model.Ex = row["Ex"].ToString();
    model.Prev_Vol = row["Prev_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Prev_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.Curr_Vol = row["Curr_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Curr_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.Mov_Vol = row["Mov_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Mov_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    decimal tonavgvol = Tools.ParseDecimalValue(row["Mov_Vol"].ToString());
    decimal currentvol = Tools.ParseDecimalValue(row["Curr_Vol"].ToString());
    if (row["Mov_Vol"].ToString() != "" && row["Curr_Vol"].ToString() != "" && tonavgvol != 0)
    	model.VolRat = (currentvol / tonavgvol).FormatAmount();
    model.Open_Vol = row["Open_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Open_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.Close_Vol = row["Close_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Close_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.AllTicks = row["AllTicks"].ToString() != "" ? Tools.ParseDecimalValue(row["AllTicks"].ToString()).FormatAmountWithoutDecimal() : "";
    model.ATR = row["ATR14"].ToString() != "" ? Tools.ParseDecimalValue(row["ATR14"].ToString()).FormatAmountFourDecimals() : "";
    decimal open = Tools.ParseDecimalValue(row["Open"].ToString());
    decimal close = Tools.ParseDecimalValue(row["Close"].ToString());
    if (row["Open"].ToString() != "" && row["Close"].ToString() != "" && open != 0)
    	model.PrevDay = (((close - open) / open) * 100).FormatPercent();
    model.PrevClose = row["PrevClose"].ToString() != "" ? Tools.ParseDecimalValue(row["PrevClose"].ToString()).FormatAmount() : "";
    model.DayOpen = row["DayOpen"].ToString() != "" ? Tools.ParseDecimalValue(row["DayOpen"].ToString()).FormatAmount() : "";
    decimal prevclose = Tools.ParseDecimalValue(row["PrevClose"].ToString());
    decimal dayopen = Tools.ParseDecimalValue(row["DayOpen"].ToString());
    if (row["DayOpen"].ToString() != "" && row["PrevClose"].ToString() != "" && prevclose != 0)
    	model.OpenGap = (((dayopen - prevclose) / prevclose) * 100).FormatPercent();
    model.SPYLast = row["TONSPLast"].ToString() != "" ? Tools.ParseDecimalValue(row["TONSPLast"].ToString()).FormatAmount() : "";
    model.TONOpen = row["TONOpen"].ToString() != "" ? Tools.ParseDecimalValue(row["TONOpen"].ToString()).FormatAmount() : "";
    model.TONHigh = row["TONHigh"].ToString() != "" ? Tools.ParseDecimalValue(row["TONHigh"].ToString()).FormatAmount() : "";
    model.TONLow = row["TONLow"].ToString() != "" ? Tools.ParseDecimalValue(row["TONLow"].ToString()).FormatAmount() : "";
    model.TONLast = row["TONLast"].ToString() != "" ? Tools.ParseDecimalValue(row["TONLast"].ToString()).FormatAmount() : "";
    model.EODHigh = row["EODHigh"].ToString() != "" ? Tools.ParseDecimalValue(row["EODHigh"].ToString()).FormatAmount() : "";
    model.EODLow = row["EODLow"].ToString() != "" ? Tools.ParseDecimalValue(row["EODLow"].ToString()).FormatAmount() : "";
    model.EODClose = row["EODClose"].ToString() != "" ? Tools.ParseDecimalValue(row["EODClose"].ToString()).FormatAmount() : "";
    model.SPYClose = row["EODSPClose"].ToString() != "" ? Tools.ParseDecimalValue(row["EODSPClose"].ToString()).FormatAmount() : "";
    model.PostVWAP = row["PostVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["PostVWAP"].ToString()).FormatAmount() : "";
    model.PreVWAP = row["PreVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["PreVWAP"].ToString()).FormatAmount() : "";
    model.MainVWAP = row["MainVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["MainVWAP"].ToString()).FormatAmount() : "";
    model.AllVWAP = row["AllVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["AllVWAP"].ToString()).FormatAmount() : "";
    model.EODVWAP = row["EODVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["EODVWAP"].ToString()).FormatAmount() : "";
    
    decimal tonlast = Tools.ParseDecimalValue(row["TONLast"].ToString());
    decimal eodhigh = Tools.ParseDecimalValue(row["EODHigh"].ToString());
    decimal eodlow = Tools.ParseDecimalValue(row["EODLow"].ToString());
    decimal tonhigh = Tools.ParseDecimalValue(row["TONHigh"].ToString());
    decimal tonlow = Tools.ParseDecimalValue(row["TONLow"].ToString());
    decimal eodclose = Tools.ParseDecimalValue(row["EODClose"].ToString());
    decimal oedspclose = Tools.ParseDecimalValue(row["EODSPClose"].ToString());
    decimal tonsplast = Tools.ParseDecimalValue(row["TONSPLast"].ToString());
    
    // еще где-то 100-150 строчек в таком же духе

    ADO.NET во все поля.
    Бизнес-логика? Что это такое?

    P.S. У класса model все свойства типа string, у всех decimal переменных потом тоже вызывается ToString().

    vertu, 11 Апреля 2014

    Комментарии (15)
  3. Assembler / Говнокод #15608

    +137

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    ascdec proc near
    mov di,0
    mov si,0
    xor dx,dx
    mov bx,offset buf
    add bx,10
    mov cx,11
    lo0:
    dec bx
    dec cx
    jcxz ex0
    mov al,[bx]
    cmp al,255
    je lo0
    lo1:
    sub al,30h 
    push bx
    push cx
    mov bx,offset deci
    xor dx,dx
    mov cx,word ptr[bx+2]
    mov bx,word ptr[bx]
    mov ah,0
    call mult32 
    add di,ax
    adc si,dx
    mov bx,offset deci
    mov ax,[bx]
    mov dx,[bx+2]
    call multen
    mov bx,offset deci
    mov [bx],ax
    mov [bx+2],dx
    pop cx
    pop bx
    dec bx
    dec cx
    jcxz ex0
    mov al,[bx]
    jmp lo1
    ex0:
    mov ax,di
    mov dx,si
    test dx,8000h
    jz enda
    jmp error
    enda:
    cmp minus,2dh
    jne pl1
    call ccc
    pl1:
    ret
    ascdec endp
    multen proc near
    push bx
    push cx
    mov bx,10
    mov cx,0
    call mult32
    pop cx
    pop bx
    ret
    multen endp
    mult32 proc near 
    push si
    push di
    push dx
    push ax
    test dx,8000h 
    jz ml
    call ucc
    push dx
    push ax
    ml:
    mov dx,cx
    mov ax,bx
    test dx,8000h  
    jz ml0
    call ucc 
    mov bx,ax
    mov cx,dx
    ml0:
    pop ax
    pop dx
    mov si,0
    mov di,0
    mul bx ;AX*BX
    mov di,ax
    mov si,dx
    pop ax
    mul cx ;AX*CX
    add si,ax
    pop dx
    ucc proc near
    dec ax
    sbb dx,0
    not ax
    not dx
    ret
    ucc endp

    Превращение строки в число.

    Abbath, 27 Марта 2014

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

    +137

    1. 1
    if ($params['provider'] == PROVIDER_GOOGLE && 0) {

    Очевидно, /*...*/ показалось слишком сложным.

    Lowezar, 19 Февраля 2014

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

    +137

    1. 1
    System.Drawing.Color.FromArgb(((int)(((byte)(249)))), ((int)(((byte)(249)))), ((int)(((byte)(249)))));

    taburetka, 07 Февраля 2014

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

    +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
    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
    #define SPLICE(a,b) SPLICE_1(a,b)
    #define SPLICE_1(a,b) SPLICE_2(a,b)
    #define SPLICE_2(a,b) a##b
     
     
    #define PP_ARG_N( \
              _1,  _2,  _3,  _4,  _5,  _6,  _7,  _8,  _9, _10, \
             _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
             _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
             _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
             _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
             _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
             _61, _62, _63, N, ...) N
     
    /* Note 63 is removed */
    #define PP_RSEQ_N()                                        \
             62, 61, 60,                                       \
             59, 58, 57, 56, 55, 54, 53, 52, 51, 50,           \
             49, 48, 47, 46, 45, 44, 43, 42, 41, 40,           \
             39, 38, 37, 36, 35, 34, 33, 32, 31, 30,           \
             29, 28, 27, 26, 25, 24, 23, 22, 21, 20,           \
             19, 18, 17, 16, 15, 14, 13, 12, 11, 10,           \
              9,  8,  7,  6,  5,  4,  3,  2,  1,  0
     
    #define PP_NARG_(...)    PP_ARG_N(__VA_ARGS__)    
     
    /* Note dummy first argument _ and ##__VA_ARGS__ instead of __VA_ARGS__ */
    #define PP_NARG(...)     PP_NARG_(_, ##__VA_ARGS__, PP_RSEQ_N())
     
    #define NARG(...)     func(PP_NARG(__VA_ARGS__), __VA_ARGS__)
     
    #define INCR 20
     
    #define FIELD_0(...)
     
    #define FIELD_1(field, ...) \
      INCR+field
     
    #define FIELD_2(field, ...) \
      INCR+field, FIELD_1(__VA_ARGS__)
     
    #define FIELD_3(field, ...) \
      INCR+field, FIELD_2(__VA_ARGS__)
     
    #define FIELD_4(field, ...) \
      INCR+field, FIELD_3(__VA_ARGS__)
     
    #define FIELD_5(field, ...) \
      INCR+field, FIELD_4(__VA_ARGS__)
     
    #define FIELD_5(field, ...) \
      INCR+field, FIELD_4(__VA_ARGS__)
     
    #define FIELD_6(field, ...) \
      INCR+field, FIELD_5(__VA_ARGS__)
     
    #define FIELD_7(field, ...) \
      INCR+field, FIELD_6(__VA_ARGS__)
     
    #define FIELD_8(field, ...) \
      INCR+field, FIELD_7(__VA_ARGS__)
     
    #define FIELD_9(field, ...) \
      INCR+field, FIELD_8(__VA_ARGS__)
     
    #define FIELD_10(field, ...) \
      INCR+field, FIELD_9(__VA_ARGS__)
     
    #define FIELD_11(field, ...) \
      INCR+field, FIELD_10(__VA_ARGS__)
    //..... дальше лень ...
     
    #define FIELDS_(N, ...) \
      SPLICE(FIELD_, N)(__VA_ARGS__)
     
    #define FIELDS(...) \
      FIELDS_(PP_NARG(__VA_ARGS__), __VA_ARGS__)
     
     
    a = { FIELDS('p', 'a', 's', 's', 'w', 'o', 'r', 'd') }

    Примитивное компил-тайм шифрование строки через сишный препроцессор. На выходе получаем

    a = { 20 +'p', 20 +'a', 20 +'s', 20 +'s', 20 +'w', 20 +'o', 20 +'r', 20 +'d' };

    Базируется на http://smackerelofopinion.blogspot.com/2011/10/determining-number-of-arguments-in-c.html

    j123123, 06 Февраля 2014

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

    +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
    public static string AddControlDigits(string input)
    {
          if (String.IsNullOrEmpty(input))
              return "";
          try
          {
              XDocument doc = XDocument.Parse(input.JavaSubString(input.IndexOf("<contracts>"), input.IndexOf("</contracts>") + "</contracts>".Length));
              String s = new String(doc.ToString().ToCharArray());
                    
              XElement rootElement = doc.Root.Element("list_item");
    
              string basicNumber = rootElement.Element("basicNumber").Value;
              string endNumber = rootElement.Element("endNumber").Value;
              string loanCaseNumber = rootElement.Element("loanCaseNumber").Value;
              string loanCaseComplementNumber = rootElement.Element("loanCaseComplementNumber").Value;
              string bridgeLoanComplementNumber = rootElement.Element("bridgeLoanComplementNumber").Value;
    
              int checkNumber = CalcCheckDigitCU(basicNumber + endNumber);
              int loanCaseCheckNumber = calcCheckDigitUP(loanCaseNumber);
              int bridgeLoanCheckNumber = CalcCheckDigitCU(basicNumber + bridgeLoanComplementNumber);
    
              rootElement.Add(new XElement("checkNumber", checkNumber));
              rootElement.Add(new XElement("loanCaseCheckNumber", loanCaseCheckNumber));
              rootElement.Add(new XElement("bridgeLoanCheckNumber", bridgeLoanCheckNumber));
    
              input = input.Replace(s, doc.ToString());
    
              return "";
         }
         catch (Exception ex)
         {
             throw;
          }
     }

    жопа

    taburetka, 10 Января 2014

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

    +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
    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
    using System;
     using System.Collections.Generic;
     namespace Builder
     {
      public class MainApp
      {
        public static void Main()
        {
          // Create director and builders
          Director director = new Director();
     
          Builder b1 = new ConcreteBuilder1();
          Builder b2 = new ConcreteBuilder2();
     
          // Construct two products
          director.Construct(b1);
          Product p1 = b1.GetResult();
          p1.Show();
     
          director.Construct(b2);
          Product p2 = b2.GetResult();
          p2.Show();
     
          // Wait for user
          Console.Read();
        }
      }
      // "Director"
      class Director
      {
        // Builder uses a complex series of steps
        public void Construct(Builder builder)
        {
          builder.BuildPartA();
          builder.BuildPartB();
        }
      }
      // "Builder"
      abstract class Builder
      {
        public virtual void BuildPartA(){}
        public virtual void BuildPartB(){}
        public virtual Product GetResult(){}
      }
      // "ConcreteBuilder1"
      class ConcreteBuilder1 : Builder
      {
        private readonly Product product = new Product();
        public override void BuildPartA()
        {
          product.Add("PartA");
        }
        public override void BuildPartB()
        {
          product.Add("PartB");
        }
        public override Product GetResult()
        {
          return product;
        }
      }
      // "ConcreteBuilder2"
      class ConcreteBuilder2 : Builder
      {
        private readonly Product product = new Product();
        public override void BuildPartA()
        {
          product.Add("PartX");
        }
        public override void BuildPartB()
        {
          product.Add("PartY");
        }
        public override Product GetResult()
        {
          return product;
        }
      }
      // "Product"
      class Product
      {
        private readonly List<string> parts = new List<string>();
        public void Add(string part)
        {
          parts.Add(part);
        }
        public void Show()
        {
          Console.WriteLine("\nProduct Parts -------");
          foreach (string part in parts)
            Console.WriteLine(part);
        }
      }
     }

    "Хороший","годный" пример паттерна билдер с википедии, не соответствующие лежащей там же Uml схеме чуть больше чем полностью

    Схема
    http://upload.wikimedia.org/wikipedia/ru/2/28/Builder.gif

    kegdan, 29 Декабря 2013

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

    +137

    1. 1
    var romans = "I II III IV".Split(' ');

    Rez, 17 Декабря 2013

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

    +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
    if (!string.IsNullOrEmpty(date))
    			{
    				var result = date.Split('.');
    				filter.TenderDate.Start = new DateTime(
    					Convert.ToInt16(result[2]),
    					Convert.ToInt16(result[1]),
    					Convert.ToInt16(result[0]),
    					0,
    					0,
    					0);
    				filter.TenderDate.End = new DateTime(
    					Convert.ToInt16(result[2]),
    					Convert.ToInt16(result[1]),
    					Convert.ToInt16(result[0]),
    					23,
    					59,
    					59);
    			}

    Парсинг дат? Не, не слышал.

    xumix, 14 Декабря 2013

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

    +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
    catch(Exception ex)
    {
        try
        {
            insertAction(TXTextControl.StringStreamType.PlainText);
            GcmExceptionHandlerForm.ShowException(ex);
        }
        catch (Exception ex2)
        {
                GcmExceptionHandlerForm.ShowException(ex2);
        }
    }

    Что-то пошло не так...

    minuzZ, 29 Ноября 2013

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