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

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

    +126

    1. 1
    2. 2
    3. 3
    4. 4
    @echo off
    chcp 1251
    mygame.exe
    chcp 866

    Оттуда.

    LispGovno, 30 Января 2014

    Комментарии (36)
  3. PHP / Говнокод #13853

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $count = count($array);
    
    // Говорю коллеге: "У тебя там деление на ноль, исправь". 
    // После этого появилось следующее...
    if ( $count == 0 ) $count = 1;
    
    $result = (int) ((1/$count) * SOME_VALUE1 + SOME_VALUE2);

    Код, блять, Хемминга

    bot, 26 Сентября 2013

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

    −1

    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
    #include <iostream>
    using namespace std;
    
    struct NG
    {
    	template<class T>
    	struct get
    	{
    		typedef typename T::f type;
    	};
    };
    
    template <typename T, typename NameGetter>
    struct has_member_impl
    {
        typedef char matched_return_type;
        typedef long unmatched_return_type;
        
        template <typename C>
        static matched_return_type f(typename NameGetter::template get<C>*);
        
        template <typename C>
        static unmatched_return_type f(...);
        
    public:
        static const bool value = (sizeof(f<T>(0)) == sizeof(matched_return_type));
    };
    
    template <typename T, typename NameGetter>
    struct has_member{
       enum { value = has_member_impl<T, NameGetter>::value };
     };
     
     class T{};
    
    int main() {
    	cout<<has_member<T, NG>::value;
    	return 0;
    }

    http://ideone.com/4LDGhZ

    LispGovno, 04 Сентября 2013

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

    +9

    1. 1
    2. 2
    3. 3
    HRESULT hr = ReadGenericXMLFile(srcStorage, pagePath, result);
      if (hr == S_FALSE) return STG_E_FILENOTFOUND;  // File must exist
      if (FAILED(hr)) return hr;

    Могу понять, обратное, когда вызывающая функция просто возвращает "false" при любом неудачном вызове внутренней функции: нет файла / нет доступа / runtime error и т.д. Здесь же наоборот, при "общем" неудачном вызове внутренней функции возвращается "конкретное" сообщение об ошибке.

    Fogbit, 25 Июля 2013

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

    +135

    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
    switch (curWpn)
    {
        case WeaponType.Doublegun: DrawNumber(doublegunAmmo, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, doublegunAmmo > 0 ? Color.White : Color.Red); spriteBatch.Draw(doublegunI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
        case WeaponType.Grenade: DrawNumber(grenadeCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, grenadeCnt > 0 ? Color.White : Color.Red); spriteBatch.Draw(grenadeI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), grenadeTimeout > 0.0f ? Color.Red : Color.White); break;
        case WeaponType.Knife: spriteBatch.Draw(knifeI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
        case WeaponType.Launcher: DrawNumber(rocketCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, rocketCnt > 0 ? Color.White : Color.Red); spriteBatch.Draw(launcherI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), launchTimeout > 0.0f ? Color.Red : Color.White); break;
        case WeaponType.Revolver: spriteBatch.Draw(revolverI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
        case WeaponType.Cannon: DrawNumber(cannonAmmo, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, cannonAmmo > 0 ? Color.White : Color.Red); spriteBatch.Draw(cannonI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), cannonTimeout > 0.0f ? Color.Red : Color.White); break;
        case WeaponType.Laser: DrawNumber(laserAmmoCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, laserAmmoCnt > 0 ? Color.White : Color.Red); break;
        case WeaponType.Minigun: DrawNumber(minigunAmmoCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, minigunAmmoCnt > 0 ? Color.White : Color.Red); break;
    }
    //в другом месте
    switch (curWpnIndex)
    {
        case 0: curWpn = WeaponType.Knife; break;
        case 1: curWpn = WeaponType.Revolver; break;
        case 2: curWpn = WeaponType.Doublegun; break;
        case 3: curWpn = WeaponType.Laser; break;
        case 4: curWpn = WeaponType.Minigun; break;
        case 5: curWpn = WeaponType.Rifle; break;
        case 6: curWpn = WeaponType.Grenade; break;
        case 7: curWpn = WeaponType.Launcher; break;
        case 8: curWpn = WeaponType.Cannon; break;
    }

    Это неописуемо. Нашел у себя...
    Видимо, придется снова идти мыться.

    RaZeR, 15 Июля 2013

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

    +83

    1. 1
    2. 2
    3. 3
    4. 4
    while (today.before(endTrial)) {
    	today.add(Calendar.DAY_OF_MONTH, 1);
    	daysBetween++;
    }

    считаем разницу между двумя датами

    wooddy, 02 Июля 2013

    Комментарии (36)
  8. Pascal / Говнокод #13210

    +76

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function IPP (var i: integer): integer;
    begin
      Result := i;
      Inc(i);
    end;

    TarasB, 21 Июня 2013

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

    −108

    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
    - (void) fixUIAfterRotation: (UIInterfaceOrientation) interfaceOrientation
    {
    	[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:UIInterfaceOrientationIsPortrait(interfaceOrientation)? @"bg_new.png":@"bg_new_90.png"]]];
      	NSString *path = [[NSBundle mainBundle] bundlePath];
    	NSURL *baseURL = [NSURL fileURLWithPath:path];
    	NSString *htmlStr;
    	webError = NO;
        orient = UIInterfaceOrientationIsPortrait(interfaceOrientation)? 1:2;
        float width_ = [[UIScreen mainScreen] bounds].size.height;
        viewNews.frame = isRotation? (UIInterfaceOrientationIsPortrait(interfaceOrientation)? 
               CGRectMake(0, 0, width_, 240):CGRectMake(0, 0, width_, width_ - 90)):(UIInterfaceOrientationIsPortrait(interfaceOrientation)? CGRectMake(0, 0, 320, width_ - 81):CGRectMake(0, 0, width_, 240));
        isRotation = isRotation? NO:isRotation;
        
    #if defined(PRO_PROJECT)    
     	if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
    	{
    		htmlStr = [NSString stringWithFormat:@"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" 
                              \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\">
                               <head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Untitled Document</title>
                               <style>body {margin:0px; padding:0px; font:13px arial; background:none;}
                               a {text-decoration:underline; color:#fbcf04; font-weight:bold; !important;} a:hover {text-decoration:none;}
                               .title{background:#575757 left top repeat-x; font:bold 15px Arial; color:#FFF; padding:14px 30px 0px 0px; height:31px; 
                               border-bottom:1px solid #000000; line-height:14px}.titleIm{background:#575757 left top repeat-x; padding:13px 8px 13px 13px; height:31px; 
                               border-bottom:1px solid #000000;}.news_body {border-top:1px solid #414141; padding:10px 14px 14px 14px; 
                               color:#FFF; line-height:19px; background:#3d3d3d;}.news_body p {padding-top:0px;}</style></head>
                              <body><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"320\" height=\"388\"><tr><td width=\"75\" valign=\"top\" class=\"titleIm\">
                              <img src=%@ height=\"70\" width=\"70\"></td><td valign=\"top\" class=\"title\">%@ 
                              <div style=\"font:11px Arial; color:#858585; line-height:18px;\">%@</div></td></tr><tr>
                              <td colspan=\"2\" valign=\"top\" class=\"news_body\">%@</td></tr></table></body></html>",
                               imageName, [newsDescription objectForKey:@"titleNews"], 
                               [CORENewsTitleList getDataString:[newsDescription objectForKey:@"dateNews"]], 
                               [newsDescription objectForKey:@"discriptionNews"]];
    	}
    	else
    	{
    		htmlStr = [NSString stringWithFormat:@"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" 
                              \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\">
                             <head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Untitled Document</title>
                             <style>body {margin:0px; padding:0px; font:13px arial; background:none;}
                             a {text-decoration:underline; color:#fbcf04; font-weight:bold; !important;}a:hover {text-decoration:none;}
                             .title {background:#575757 left top repeat-x; font:bold 15px Arial; color:#FFF; padding:14px 30px 0px 0px; height:31px; 
                              border-bottom:1px solid #000000; line-height:14px}.titleIm {background:#575757 left top repeat-x; padding:13px 8px 13px 13px; height:31px; 
                              border-bottom:1px solid #000000;}.news_body {border-top:1px solid #414141; padding:10px 14px 14px 14px; 
                              color:#FFF; line-height:19px; background:#3d3d3d;}.news_body p {padding-top:0px;}</style></head>
                              <body><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"%f\" height=\"240\"><tr><td width=\"75\" valign=\"top\" class=\"titleIm\">
                              <img src=%@ height=\"70\" width=\"70\"></td><td valign=\"top\" class=\"title\">%@ 
                              <div style=\"font:11px Arial; color:#858585; line-height:18px;\">%@</div></td></tr><tr>
                              <td colspan=\"2\" valign=\"top\" class=\"news_body\">%@</td></tr></table></body></html>",
                              width_, imageName, [newsDescription objectForKey:@"titleNews"], 
                              [CORENewsTitleList getDataString:[newsDescription objectForKey:@"dateNews"]], 
                              [newsDescription objectForKey:@"discriptionNews"]];
    	}
    #else
        if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
    	{
                    // тот же упоротый код, что и выше, за исключением цветов для бэкграунда и надписей.
            }
    	else
    	{
                    // тот же упоротый код, что и выше, за исключением цветов для бэкграунда и надписей.
    	}
    #endif
    	[viewNews loadHTMLString:htmlStr baseURL:baseURL];
    }

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

    QuickNick, 30 Мая 2013

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

    +110

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    int strnlen(const char *s, int size)
    {
            int i;
            for(i=0; i<size; i++) if(!*s) break;
            return i;
    }

    tz-lom, 18 Января 2013

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

    +135

    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
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #define MAXSIZE 512
    
    typedef struct word
    {
    	char wordBody[MAXSIZE];
    	int count;
    	struct word* next;
    } Word;
    
    Word* alloc(char* incomeWord)
    {
    	Word* ret;
    	ret = (Word*)malloc(sizeof(Word));
    	ret->count=1;
    	ret->next=NULL;
    	strcpy(ret->wordBody, incomeWord);
    }
    
    void insert(Word **n, char* incomeWord)
    {
    	Word** p_p_n;
    	int h=0;
    
    	if(*n==NULL)
    	{
    		*n = alloc(incomeWord);
    		return;
    	}
    
    	for(p_p_n = n; *p_p_n!=NULL; p_p_n = &(*p_p_n)->next)
    	{
    		if((strcmp(incomeWord,&(*p_p_n)->wordBody))==0)
    		{
    			(*p_p_n)->count++;
    			return;
    		}
    	}
    
    	for(p_p_n = n; *p_p_n!=NULL; p_p_n = &(*p_p_n)->next)
    	{
    		Word* ins = alloc(incomeWord);
    		Word* temp = *p_p_n;
    		Word** tt;
    		int is=0;
    		tt=p_p_n;
    		ins->next=temp;
    		*p_p_n = ins;
    		break;
    	}
    }
    
    void print(Word* n)
    {
    	while(n!=NULL) {
    		if(n->count > 1)
    		{
    			printf("%s %d\n", n->wordBody, n->count);
    		}
    		n=n->next;
    	}
    }
    
    int main(void)
    {
    	char buf[MAXSIZE]={'\0'};
    	FILE *fr;
    	Word* sez=NULL;
    	fr=fopen("Text1.txt", "r");
    
    	while(!feof(fr))
    	{
    		fscanf(fr,"%s",buf);
    		insert(&sez,buf);
    	}
    
    	print(sez);
    	printf("\n%d\n", sizeof(sez));
    	fclose(fr);
    	return 0;
    }

    Считаем сколЬко раз каждое слово встречается в текстовом файле. Программа выполняется 6.5 минут с файлом размером 850 килобайт.

    taburetka, 25 Декабря 2012

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