1. C# / Говнокод #13426

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public class DataLayer
    {
    ...
    public List<Employee> GetEmployees() { ... }
    public List<Department> GetDepartments() {...}
    public List<Roles> GetRoles() {...}
    }

    Обратил внимание, что некоторые коллеги любят использовать в качестве возвращаемых типов не обычные массивы, а обязательно List<T>.
    Долго гадал, что-ж такая за практика интерсная, на стеке прям несколько вопросов подрял.
    Затем, обратил внимание, что все они используют в качестве основного инструмента паттерн MVC.
    Проштудировав самые известные книжки по MVC, таки нашёл виновника:
    http://www.ozon.ru/context/detail/id/19064535/ - Программирование на основе Microsoft ASP.NET MVC (Дино Эспозито)
    Везде где только можно, всё просто обделано LIst'ами. Даже данные передаваемые во View...

    TauSigma, 15 Июля 2013

    Комментарии (134)
  2. 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)
  3. Куча / Говнокод #13423

    +125

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    wrs(S):-put_char('\"'), wrsi(S).
    wrsi([C|S]):-put_char(C), wrsi(S).
    wrsi([]):-put_char('\"').
     
    wrl(S):-put_char('['), wrli(S), put_char(']').
    wrli([C|[O|S]]):-wrs(C), put_char(','), wrli([O|S]).
    wrli([C]):-wrs(C).
     
    :- wrl(["dog", "cat", "canary"]).

    Курю правильные примеры кода на прологе. PrologGovno ждите во всех кинотеатрах страны.
    http://ideone.com/L4vIKs
    Почему вместо того чтобы пользоваться стандартной функцией вывода списков или строк - автор рекомендует это? Я код правда поправил, а то хаскельных скобок (я уже без них не могу) не было и запятую в конце списка выдавало.

    HaskellGovno, 15 Июля 2013

    Комментарии (14)
  4. Си / Говнокод #13422

    +126

    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
    typedef struct {
      uint32_t id;
      char * title;
    } dbrow_t;
    
    typedef struct {
      char * context;
      dbrow_t dbrow;
    } parser_context_t;
    
    typedef enum {    
      bad_char = 0,
      identifer,
      number,
      state_end_context,  
      state_end_line
    } type_t;
    
    type_t ch_d[0x100] = { [0] = state_end_line, [1 ... 0xff] = bad_char, ['0' ... '9'] = number, ['a' ... 'z'] = identifer, ['\n'] = state_end_context};
    
    inline char * do_other_type(char * p, type_t type) { while(ch_d[*(++p)] == type); return p;}
    
    static inline uint64_t bad_char_headler(parser_context_t * context) { context->context = do_other_type(context->context, bad_char); return 1;}
    
    static inline uint64_t number_headler(parser_context_t * context) {
      uint32_t id = 0; char * p = context->context;
      while(({ id *= 10; id += (*p - '0'); ch_d[*(++p)];}) == number);
      context->dbrow.id = id; context->context = p;
      return 1;
    }
    
    static inline uint64_t identifer_headler(parser_context_t * context) {
      char * p = context->context, * title = context->dbrow.title;
      char * end_identifer = do_other_type(p, identifer);
      memcpy(title, p, (end_identifer - p)); *(title + (end_identifer - p)) = 0;
      context->context = end_identifer;
      return 1;
    }
    
    static inline uint64_t end_context_headler(parser_context_t * context) {
      context->context = do_other_type(context->context, state_end_context);
      if(context->dbrow.id && *context->dbrow.title)
        fprintf(stderr, "id = %u, title = %s\n", context->dbrow.id, context->dbrow.title);
      context->dbrow.id = 0, *context->dbrow.title = 0;
      return 1;
    }
    
    static inline uint64_t end_line_headler(parser_context_t * context) { return 0; }
    
    typedef uint64_t(*headler_ptr_t)(parser_context_t *);
    
    headler_ptr_t headlers[] = { [bad_char] = bad_char_headler, [identifer] = identifer_headler, [number] = number_headler, [state_end_context] = end_context_headler, [state_end_line] = end_line_headler };
    
    int main(void) {
        char * content = strcpy(malloc(50), "1|raz\n11|dva\n21|tri\n31|shestb\n5000|test\n|||\n||\n|\n");
        parser_context_t context = (parser_context_t){ .context = content, .dbrow = (dbrow_t){ .title = malloc(1000)}};
        while(headlers[ch_d[*(context.context)]](&context));
        return 0;
    }

    Решил пацанам показать как писать парсер - вышло говно. Хотя так-то должно тащить - забенчите кто-нибудь, настолько это гумно медленнее strtok()'а.

    superhackkiller1997, 15 Июля 2013

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

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public void BuildInsertClause(OleDbCommand cmd, ObjectState objState)
            {
                  StringBuilder builder = new StringBuilder();
                  ..........
                  cmd.CommandText = builder.ToString() + "(" + columns.ToString() + ") VALUES (" +
                  values.ToString() + ")";
            }

    http://solidcoding.blogspot.ru/2008/01/linq-to-excel-provider-25.html
    Еще много смешного, для затравки:

    object val = reader[col.GetSelectColumn()];
    if (val is DBNull)
    {
    val = null;
    }

    neeedle, 15 Июля 2013

    Комментарии (17)
  6. PHP / Говнокод #13420

    +106

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    $items = array('palto','noski','shapki');
        $colors = array('red','black','white');
        $materials = array('kozha','meh','aluminij');
    
        foreach($items as $item) {
          foreach($colors as $color) {
            foreach($materials as $material) {
              echo $item.'-'.$color.'-'.$material;
              echo '</br>';
            }
          }
        }

    Задача:
    Группа 1.
    Пальто, Шапки, Носки
    Группа 2.
    Красный, Синий, Зеленый
    Группа 3.
    Мех, Кожа

    Необходимы комбинации следующего вида, пример:
    1) Пальто - красный - мех
    2) Пальто - красный - кожа
    3) Пальто - синий - мех
    ....
    N) Носки - зеленый - кожа

    При том условии, что группа занимает только свое место в порядке. Т.е. пальто не может быть 2-ым или 3-им словом в комбинации.

    Vasiliy, 15 Июля 2013

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

    +15

    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
    #include<iostream>
    #include<set>
    #include<vector>
    #include<hash_set>
    #include<math.h>
    #include<stdlib.h>
    using namespace std;
    inline int po(int a,int b){
    int ans =1;
    for(int i=0;i<b;++i)ans*=a;
    return ans;
    }
    inline bool isnotsq(int a){
    	return sqrt(0.0+a)!=int(sqrt(a+0.0));
    }
    
    int main(){
    	int t,n,k;
    	cin>>t;
    	int SQRT  = 100000,primes[100100]={0};
    	primes[2]=1;
    	vector<int> pr;
    	pr.push_back(2);
    	for(int i = 3;i<=SQRT;i+=2){
    		if(primes[i]==0) {
    			pr.push_back(i);
    			for(int j = 2*i;j<=SQRT;j+=i) primes[j]=1;
    		}
    	}
    	while(t--){
    		cin>>n>>k;
    		int nn=n;
    		int divisors[1001];
    		int divisecount[1001]={0};
    		int divc=0;
    		int count = 0;
    		for(int i =0;i<pr.size();++i){
    			if(n%pr[i]==0) divisors[divc++]=pr[i];
    			while(n%pr[i]==0) divisecount[divc-1]++,n/=pr[i],count++;
    		}
    		if(n!=1) divisors[divc++]=n,divisecount[divc-1]=1;
    		//for(int i =0;i<divc;++i) cout<<divisors[i]<<' '<<divisecount[i]<<'\n';
    		vector< int> cbused;
    		vector<int> rem;
    		rem.push_back(0);
    		cbused.push_back(1);
    		
    		for(int i =0;i<divc;++i){
    			int cs = cbused.size();
    			for(int j =0;j<cs;++j){
    				int cc = divisors[i];
    				int ops=1;
    				while(1){
    					if(nn%(cbused[j]*cc)==0) {
    						if(isnotsq(cbused[j]*cc)) 
    							cbused.push_back(cbused[j]*cc),rem.push_back(rem[j]+ops);
    					}
    					else break;
    					cc*=divisors[i];
    					ops+=1;
    				}
     			}
    		}
    		//for(int  i = 0;i<cbused.size();++i) cout<<cbused[i]<<' '<<rem[i]<<'\n';
    		int siz= cbused.size();
    		set< pair<int,int > > anse;
    		anse.insert(make_pair(1,0));
    		for(int j = 1;j<siz;++j){
    			for(int i = cbused[j],k=1;nn%i==0;i*=cbused[j],k++) if(i%2==1) anse.insert(make_pair(i,k));
    		}
    		for(int i = 1;i<siz;++i){
    				vector<pair<int , int> > toa;
    				for(set< pair<int,int> >::iterator it=anse.begin();it!=anse.end();it++){
    					if(nn%(cbused[i]*it->first)==0&&it->second<k) toa.push_back(make_pair(cbused[i]*it->first,it->second+1));
    					for(int q=0;q<toa.size();q++) anse.insert(toa[q]);
    				}
    			}
    		
    		bool f = false;
    		for(set< pair<int,int> >::iterator it=anse.begin();it!=anse.end();it++){
    			if(it->first==nn&&it->second==k) f=true;
    		}
    		cout<<(f?"YES":"NO")<<"\n";
    		if(t==0) return 0;
    	}
    }

    Задано целое положительное число n. Выясните, может ли оно быть представлено в виде произведения k целых положительных чисел, ни одно из которых не является квадратом целого числа.
    (с яндекс.алгоритма)

    AvadaKedavra, 14 Июля 2013

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

    +70

    1. 1
    final int mazeBlockSize = mazeBlock.getIconWidth();       // it is square, OKAY?!

    Как я пакмена писал

    vortexx1, 13 Июля 2013

    Комментарии (19)
  9. Си / Говнокод #13416

    +129

    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
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    void swap (char *x, char *y)
    {
        char temp;
        temp = *x;
        *x = *y;
        *y = temp;
    }
     
    void permute(char *a, int i, int n)
    {
        int j;
        if (i == n)
        printf("%s\n", a);
        else
        {
            for (j = i; j <= n; j++)
            {
                swap((a+i), (a+j));
                permute(a, i+1, n);
                swap((a+i), (a+j));
            }
        }
    }
     
     
    int main()
    {
        char str[80] ;
        int len=0,i;
        puts("Enter a string:\n\n");
        gets(str);
        for (i=0; str[i] != '\0'; i++)
        {
            len++;
        }
        permute(str, 0, len);
        getchar();
        return 0;
    }

    Источник:
    http://www.c-program-example.com/2012/04/c-program-to-find-all-permutations-of.html

    про strlen видимо никто не слышал

    denis90, 13 Июля 2013

    Комментарии (121)
  10. JavaScript / Говнокод #13414

    +155

    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
    getCastIds:
            function(checkCast){
                var i
                  , castIds = [this.cancelBlesId]
                  ;
                if(checkCast)
                {
                    for(i = 0; i < castIds.length; i++)
                    {
                      if(Empire.asset(castIds[i]))
                      {
                        castIds.splice(i,1);
                        i--;
                      }
                    }
                }
                return castIds.length ? castIds : [0];
            }

    Выстрелим себе в ногу.

    dioteos, 12 Июля 2013

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