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

    В номинации:
    За время:
  2. Куча / Говнокод #18005

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    Кажется сбылась чья-то мечта. Калькулятор на чистом css
    
    http://habrahabr.ru/company/paysto/blog/255511/
    http://experiments.hertzen.com/css3calculator/

    blablabla2, 16 Апреля 2015

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

    +890

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    Int64 iObjectId;
    
    public Int64 ObjectId
    {
        get { return iObjectId; }
        set {
             if (iObjectId == null) { value = 0; } else value = iObjectId;
        }
    }

    Помимо того, что условие (iObjectId == null) никогда не выполняется, сеттер еще и делает свойство ObjectId фактически readonly.
    (Авторское форматирование кода сохранено.)

    svetkeen, 15 Апреля 2015

    Комментарии (11)
  4. Python / Говнокод #17977

    −124

    1. 1
    2. 2
    3. 3
    if __name__ == "__main__":
        def f():
            pass

    Динамичненько

    xyilka, 11 Апреля 2015

    Комментарии (11)
  5. Python / Говнокод #17967

    −117

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    self.symbol_ban = {".":".00",  "!":".01",  "@":".02",  "#":".03",  "$":".04",  "%":".05",  "^":".06",
                               "&":".07",  "*":".08",  "+":".09", "\n":".10", "\t":".11", "\"":".12", "\'":".13",
                               "/":".14",  "<":".15",  ">":".16",  '`':".17", '\\':".19",  " ":".20",  "=":".21",
                               "(":".22",  ")":".23"}
    new_path = map((lambda x, y: [x, y]), ["a_"+"".join([j if (j not in self.symbol_ban) else self.symbol_ban[j] for j in i[0]])   for i in path], [j[1] if j[1] in ("dir", "file") else self.Ex(1)    for j in path])

    часть sax парсера xml для экранирования входных данных, писал для бакалаврской. диплом отдали

    socrat775, 09 Апреля 2015

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

    −352

    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
    97. 97
    98. 98
    99. 99
    - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    	UITableViewCell *cell = nil;
    
    	if (indexPath.row == self.titles.count - 1)
    	{
    		cell = [tableView dequeueReusableCellWithIdentifier:@"settingButtonCell" forIndexPath:indexPath];
    
    		SWSettingButtonCell *scell = (SWSettingButtonCell *) cell;
    
    		[scell.settingButton setTitleForAllStates:self.titles[indexPath.row]];
    
    		[scell.settingButton bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];
    
    		scell.settingIcon.visible = YES;
    
    		@weakify(self);
    		[scell.settingButton bk_addEventHandler:^(id sender) {
    			[UIAlertView bk_showAlertViewWithTitle:@"Logout"
    										   message:@"Do you want to logout?"
    								 cancelButtonTitle:@"NO"
    								 otherButtonTitles:@[@"YES"]
    										   handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
    											   @strongify(self);
    
    											   if (buttonIndex != 0)
    											   {
    												   [[SWCore instance] logout];
                                                       // fix
                                                       [SVProgressHUD show];
                                                       // end fix
    											   }
    										   }];
    		}                      forControlEvents:UIControlEventTouchUpInside];
    	}
    	else if (indexPath.row == self.titles.count - 2)
    	{
    		cell = [tableView dequeueReusableCellWithIdentifier:@"settingButtonCell" forIndexPath:indexPath];
    
    		SWSettingButtonCell *scell = (SWSettingButtonCell *) cell;
    
    		[scell.settingButton setTitleForAllStates:self.titles[indexPath.row]];
    
    		[scell.settingButton bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];
    
    		scell.settingIcon.visible = NO;
    
    		@weakify(self);
    		[scell.settingButton bk_addEventHandler:^(id sender) {
    
    			@strongify(self);
    			[self performSegueWithIdentifier:@"pushSettingsSegue" sender:nil];
    		}                      forControlEvents:UIControlEventTouchUpInside];
    	}
    	else
    	{
    		cell = [tableView dequeueReusableCellWithIdentifier:@"settingCell" forIndexPath:indexPath];
    
    		SWSettingCell *scell = (SWSettingCell *) cell;
    
    		scell.settingLabel.text = self.titles[indexPath.row];
    		[scell.settingIcon setImage:self.icons[indexPath.row]];
    
    		switch (indexPath.row)
    		{
    			case 0:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PROFILE_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_profile_icon_on"] : [UIImage imageNamed:@"settings_profile_icon_off"];
    			}
    				break;
    
    			case 1:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_EVENTS_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_events_button_on"] : [UIImage imageNamed:@"settings_events_button_off"];
    			}
    				break;
    
    			case 2:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PHONE_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_phone_button_on"] : [UIImage imageNamed:@"settings_phone_button_off"];
    			}
    				break;
    
    			case 3:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PHOTOS_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_photos_button_on"] : [UIImage imageNamed:@"settings_photos_button_off"];
    			}
    				break;
    
    			default:
    				break;
    		}
    
    		scell.settingSwitch.tag = indexPath.row;
    		[scell.settingSwitch bk_removeEventHandlersForControlEvents:UIControlEventValueChanged];

    Один из самых классных методов cellForRowAtIndexPath что я когда-либо видел

    shadeapps, 06 Апреля 2015

    Комментарии (11)
  7. Java / Говнокод #17878

    +77

    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
    int processRequest(Request rq) {
        try {
            ... blablabla ...
            if ("".equals(object.getPrefix())) {
                throw new IllegalArgumentException(bundle.getMessage(MessageKeys.ILLEGAL_PREFIX));
            }
            ... blablabla ...
        } catch (IllegalArgumentException ex) {
            if (ex.getMessage().equals(bundle.getMessage(MessageKeys.ILLEGAL_PREFIX))) {
                return ErrorCodes.ILLEGAL_PREFIX;
            }
            return ErrorCodes.UNKNOWN_ERROR;
        }
        ... blabla ...
        return ErrorCodes.OK;
    }

    Интересный подход

    debugger, 27 Марта 2015

    Комментарии (11)
  8. bash / Говнокод #17868

    −106

    1. 1
    2. 2
    3. 3
    4. 4
    cat huiz.sh
    
    #!/bin/sh
    whois $1

    Нашёл на старом сервере.

    xvost, 26 Марта 2015

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

    +132

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    // var doc = new Document(file);
    var stream = new MemoryStream();
    file.CopyTo(stream);
    file.Position = 0;
    stream.Position = 0;
    var doc = new Document(stream);

    Ебал в рот Spire.Doc
    Нагло жует чужие потоки
    Причем только если документ - RTF
    Какого хуя вообще?

    ebal, 18 Марта 2015

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

    +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
    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
    #define poff    acurp + curp * (nSQs+2)        /*probs: offset*/
    long psum() {return  c(poff+ 1);}    long pmax()    {return c(poff+2);}
    long pn     (long n)                {return          c(poff+2+n);   }
    void setp   (long n, long x){set    (poff+2+n, x);} /*prob changes:*/ 
    void setmax         (long x){set    (poff+2,   x);} /*metasearching*/
    void setsum         (long x){set    (poff+1,   x);}
    long get2ndmax()    {long n= poff+2, x=pmax(), m=n,  s=0,end=n+nSQs;   
         do     {n++;}   while  (c(n) != x);  /*find 2nd-highest <=pmax*/     
         do     {m++;    if (s < c(m) && m !=n) s= c(m);}/*jue tncheck?*/
                 while      (s < x    && m < end);       return  s;}
    void addtoSQ(long i, long val) {long x;   /*increase prob of ith SQ*/
         if  (val < 1 || i >nSQs || i<1) return;        /*not possible!*/
         x =  psum()+val;if (x > maxint) return;   /*has max normalizer*/
         setsum (x);    /*normalizer +*/ x =  pn(i)+val; setp(i, x); 
         if (x > pmax()) setmax (x);}   /*maximal SQprob has increased */    
    void subofSQ(long i, long val) {long x;   /*decrease prob of ith SQ*/
         if  (val < 1 || i >nSQs || i<1) return;        /*not possible!*/
         x =  pn(i)-val; if (x < 0)      return;/*no neg probabilities!*/
         setsum (psum()- val);           setp(i,x);/*don't check if =0!*/   
         if (x + val  == pmax()) setmax (get2ndmax());} /*change of max*/
    void incSQ()        {long i= top();  addtoSQ(i,1);} /*top, not pop!*/
    void decSQ()        {long i= top(),  x,y,z; /*decrem prob of the SQ*/
         if  (i> nSQs   || i< 1) return;/*no such search Q number known*/
         x =  pn(i);     if     (x==0)   return;        /*SQ: already 0*/
         y  = psum();    z =     pmax();              
         if  (x == 1 &&  y    <= z+1)    stop    /*leave at least 2 SQs*/
         if  (x == z)    setmax         (get2ndmax());  /*change of max*/
         setp(i, x-1);   setsum (y-1);}                 /*normalizer -1*/
    long upSQ;          /*SQ probability:enumerator  +=  upSQ: increase*/
    void oldSQ()   {long a=pop()+ndecl,  n,i; if(a<0||a> oldp)stop/*bad*/
         n=old[a].size;  a=old[a].start;/*all SQs of old nondecl: +upSQ*/
         tncheck  n+=a;  for(i=a;i<n;i++)addtoSQ(SQ[q[i].Q],     upSQ);}
    
    void setpat()       {long i= pop(); /*instantiate my search pattern*/
         if  (i<0 || i > patp)     stop /*no such search pattern exists*/
         set (acurp,i);}/*next SQ-search defined via new probabilities!*/
    void pupat()        {long    i  =    apatp;   /*push search pattern*/ 
         if  (i>maxpat)  stop    i++;    set(apatp,i);  /*not too many?*/
         cpabn  (poff+1, acurp + 1 + i *(2+ nSQs),       2 + nSQs,  
                                         acurp + 1,      aendpats);     }  
    void popat()        {long i= apatp;  if(i==0)   stop
         set(apatp,i-1); push(i); }                /*pop search pattern*/

    Полный исходник http://www.idsia.ch/~juergen/oopscode.c

    j123123, 17 Марта 2015

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

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #define   CONC_LINE(a)  CONC(a, __LINE__)
    #define   CONC(a, b)  __CONC(a, b)
    #define __CONC(a, b)  a##b
    // ...
    int CONC_LINE(name);

    Способ присовокупить к названию переменной номер строки, где её объявили.
    Объясните кто-нибудь, почему #define CONC_LINE (a) __CONC ( a, __LINE__ ) дает: name__LINE__?

    refactor, 11 Марта 2015

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