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

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

    +79

    1. 1
    2. 2
    3. 3
    List<String> list;
    ....
    Long num = Long.parseLong( "" + list.size() );

    Самый оригинальный способ конвертации int в Long, кот. встречал в проекте )

    SIDS, 15 Октября 2012

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

    +41

    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
    int sheeps(int pole[10][10])
    {
        int i,j,f,k,r;
        int rand_chislo, rand_chislo1, ts,s; 
      
          srand(time(NULL));      
         for (i=0;i<10;i++)   
          for (j=0;j<10;j++)
          pole [i][j]=0;  
         do{ f=0;                                
            rand_chislo = 0 + rand() %10;
            rand_chislo1= 0 + rand() %10;        
            ts = 1+rand()%4;        
              if (ts==1) {for(i=0;i<3;i++) if(rand_chislo==i)f=1;}
             if (ts==2)  {for(i=7;i<10;i++) if(rand_chislo==i)f=1;}                          
              if (ts==3) {for(i=0;i<3;i++) if(rand_chislo1==i)f=1;}
             if (ts==4)  {for(i=7;i<10;i++) if(rand_chislo1==i)f=1;}       
            }
           while (f==1);
            switch (ts){
              case 1: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo-1][rand_chislo1]=1;
                      pole[rand_chislo-2][rand_chislo1]=1;pole[rand_chislo-3][rand_chislo1]=1; break;
               case 2: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo+1][rand_chislo1]=1; 
                       pole[rand_chislo+2][rand_chislo1]=1;pole[rand_chislo+3][rand_chislo1]=1; break;
             case 3: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1-1]=1;
                     pole[rand_chislo][rand_chislo1-2]=1;pole[rand_chislo][rand_chislo1-3]=1;break;
              case 4: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1+1]=1;
                      pole[rand_chislo][rand_chislo1+2]=1;pole[rand_chislo][rand_chislo1+3]=1; break; }
         
        for (k=0;k<3;k++)                                      
         {
           do{ f=0;
            rand_chislo = 0 + rand() %10;
            rand_chislo1= 0 + rand() %10;       
            ts = 1+rand()%4;       
              if (ts==1)  {if(rand_chislo!=0){ for (i=rand_chislo-2;i<rand_chislo+2;i++)
                                          for (j=rand_chislo1-1;j<=rand_chislo1+1;j++)
                                            {if (pole[i][j]!=0){f=1;}}}else f=1; }
             if (ts==2)  {if (rand_chislo!=9)  {  for (i=rand_chislo-1;i<=rand_chislo+2;i++)
                                              for (j=rand_chislo1-1;j<=rand_chislo1+1;j++)
                                              { if (pole[i][j]!=0){ f=1;}}}else f=1;  }                            
              if (ts==3) { if (rand_chislo1!=0) {   for (i=rand_chislo-1;i<=rand_chislo+1;i++)
                                                for (j=rand_chislo1-2;j<=rand_chislo1+1;j++)
                                                { if (pole[i][j]!=0){ f=1;}}}else f=1;  } 
             if (ts==4) { if (rand_chislo1!=9) {   for (i=rand_chislo-1;i<=rand_chislo+1;i++)
                                                for (j=rand_chislo1-1;j<=rand_chislo1+2;j++)
                                                { if (pole[i][j]!=0){ f=1;}}} 
                                                else f=1;   }                                  
            }
           while (f==1);
            switch (ts){
              case 1: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo-1][rand_chislo1]=1; break;
              case 2: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo+1][rand_chislo1]=1; break;
              case 3: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1-1]=1;break;
              case 4: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1+1]=1; break; }  
         }    
         for (k=0;k<2;k++)                                  
         {
           do{ f=0;
            rand_chislo = 0 + rand() %10;
            rand_chislo1= 0 + rand() %10;
          
     /*зесь еще 2 таких же while (if==1) и for k<3 и k<4 */
    
    return pole[10][10];
    }

    курсовик первокурсника "морской бой". функция расстановки кораблей

    equilibrium, 17 Сентября 2012

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

    +58

    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
    // что-то страшно мне стало
    class Mysql{
      private $db = null; 
      private $result = null; 
    //private $row = null;
     
     function __construct($dbname,$dbuser,$dbpass,$dbhost){
        $this->db = mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
        mysql_select_db($dbname) or die ("<br>Invalid query: " . mysql_error());
        mysql_query("SET NAMES utf8") or die ("<br>Invalid query: " . mysql_error());
     }
     function connect(){
        if(!$this->db){
        exit("Error connect BD!");
        }
     }
    
     function query($query){
        if(!$query){exit("No [query]");}
    	$this->result = $query = mysql_query($query) or die ("<br>Invalid query: " . mysql_error());
    	return $query;
     } 
    }

    kuler, 13 Сентября 2012

    Комментарии (21)
  5. SQL / Говнокод #11765

    −158

    1. 1
    2. 2
    3. 3
    4. 4
    SELECT ft_login,fi_system,ft_password,fk_id
    FROM users u
    INNER JOIN taccountscontent t ON u.id = t.fk_id
    WHERE u.id IN (select id from users where id=123)

    Оригинал http://www.askdev.ru/question/16663/%D0%97%D0%B0%D0%BF%D1%80%D0%BE%D1%81-%D0%BA-%D0%91%D0%94-%D0%B8-%D1%86%D0%B8%D0%BA%D0%BB-While/

    et, 13 Сентября 2012

    Комментарии (21)
  6. Ruby / Говнокод #11643

    −160

    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
    <div class="comment-content">
      		<% if comment.body.include?('[/quote]') %>
      			<% @text = Array.new %>
      			<% summ = '' %>
      			<% @text = simple_format(comment.body).split(' ') %>
      			<% namecheck = false %>
      			<% contentcheck = false %>
      			<% quotestart = false %>
      			<% donothing = true %>
      			<% quotecount = 0 %>
      			<% count_quotes = 0 %>
      			<% @text.each do |t| %>
      				<% if t.include?('[/quote]') %>
      					<% count_quotes ||= 0 %>
      					<% count_quotes += 1 %>
      				<% end %>
      			<% end %>
      			<% @text.each do |t| %>
      				<% if t.include?('[/quote]') %>
      					<% contentcheck = false %>
      					<% namecheck = false %>
      					<% t = t.gsub('[/quote]', '</div></div>') %>
      				<% elsif t.include?('[quote=') %>
      					<% namecheck = true %>
      					<% donothing = false %>
      					<% t = t.gsub('[quote=', '') %>
      				<% elsif t.include?(']') %>
      					<% t = t.gsub(']', '') %>
      				<% end %>
      				<% if donothing == false %>
      					<% if contentcheck == true and namecheck == true and t != '' and t != '<p>' and t != '</p>' %>
      						<% t = '<div class=quotecontent>' + '<div class=quotestart>' + '<div class=quotename>' + 'Цитата - ' + t + '</div>' %>
      						<% contentcheck = true %>
      						<% namecheck = false %>
      					<% elsif contentcheck == true and t != '' and t != '<p>' and t != '</p>' %>
      						<% t = '<div class=quotecontent>' + t %>
      						<% contentcheck = false %>
      					<% elsif namecheck == true and t != '' and t != '<p>' and t != '</p>' %>
      						<% t = '<div class=quotestart>' + '<div class=quotename>' + 'Цитата - ' + t + '</div>' %>
      						<% namecheck = false %>
      						<% contentcheck = true %>
      					<% end %>
      				<% end %>
      				<% summ = summ + t + ' ' %>
      			<% end %>
      		<% else %>
      			<% summ = comment.body %>
      		<% end %>
        	<%=raw simple_format(summ) %>
        </div>

    Вьюха списка комментариев. Когда это попало к верстальщику - он был мягко говоря шокирован.

    ruby-code, 24 Августа 2012

    Комментарии (21)
  7. Haskell / Говнокод #11510

    −79

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    t = 40000 -- количество итераций, чтобы выполнялось примерно 1 миллисекунду
                    -- экспериментальным путем определено, что для ideone'вских машин это значение ~40000
     
    sleep x = (apply (t*x) id x) `seq`
        ("I've waited ~" ++ show x ++ " milliseconds to tell this: 'pipisiunchik'.")
    
    -- apply применяет ф-цию f к x n раз
    apply 0 _ !x = x
    apply !n !f !x = apply (n - 1) f (f x)
     
    main = putStrLn $ sleep 1000

    Спешу представить вам плод моего безделья: чистая ф-ция sleep на Haskell!

    Тесты:
    1sec - http://ideone.com/sLxRx
    3.5sec - http://ideone.com/vn4Fd
    10sec - http://ideone.com/U8s36

    zim, 31 Июля 2012

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

    +120

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private void button4_Click(object sender, RoutedEventArgs e)
            {
                if (!rand)
                {
                   rand = true;
                }
                if (rand)
                {
                    rand = false;
                }
            } // Кнопка переключения воспроизведения в случайный режим и оборатно

    psina-from-ua, 30 Июня 2012

    Комментарии (21)
  9. PHP / Говнокод #11299

    +72

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public function isAdmin() {
            $admins = Model::factory('User')->where('access_level_id', 1)->find_many();
            $ids = array();
            foreach($admins as $admin) {
                $ids[]= $admin->id;
            }
            return in_array($this->id, $ids) ? true : false;
        }

    Метод проверки на админе из модели пользователей. Не, ну а чо.

    mr.The, 26 Июня 2012

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

    −116

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    ВЫБОР 
    КОГДА ПолФизическихЛиц.Ссылка = "Женский" 
    ТОГДА "М" 
    ИНАЧЕ "Ж" 
    КОНЕЦ

    Вот такой вот забавный запрос

    glavdir, 25 Июня 2012

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

    −47

    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
    void init_by_array64(unsigned long long init_key[],
    		     unsigned long long key_length)
    {
        unsigned long long i, j, k;
        init_genrand64(19650218ULL);
        i=1; j=0;
        k = (NN>key_length ? NN : key_length);
        for (; k; k--) {
            mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * 3935559000370003845ULL))
              + init_key[j] + j; /* non linear */
            i++; j++;
            if (i>=NN) { mt[0] = mt[NN-1]; i=1; }
            if (j>=key_length) j=0;
        }
        for (k=NN-1; k; k--) {
            mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * 2862933555777941757ULL))
              - i; /* non linear */
            i++;
            if (i>=NN) { mt[0] = mt[NN-1]; i=1; }
        }
    
        mt[0] = 1ULL << 63; /* MSB is 1; assuring non-zero initial array */ 
    }

    "Чистый и ясный код" (с)

    Fai, 24 Июня 2012

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