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

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

    +172

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    void Logger::LogString( std::string &s )
    {
    	if (s.size() > 4096) {
    		// предотвращаем слишком длиные строки в логе.
    		s.resize( 4096 );
    	}
    	m_LogStream << LogMessagePrefix() << s << std::endl;
    }

    народ пару дней понадобилось найти почему XML сообщения, размером слегка больше обычного, Xerces не принимает. идеи иссякли - пока в лог не посмотрели и не нашли вот по такому (проиллюстрированому выше) чудо принципу работающий логгер.

    Dummy00001, 10 Ноября 2010

    Комментарии (18)
  3. JavaScript / Говнокод #4471

    +122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    Код из нового  курса  Е.Попова по JS и JQuery
    
    var name = "Иваh";
    for (var i = 0; i < name.length; i++) {
        if (name.charCodeAr(i) < 1040 || name.charCodeAt(i) > 1103 {
            document.write("Найден символ: " + name.charAt(i));
        }
    }

    Vasiliy, 28 Октября 2010

    Комментарии (18)
  4. Ruby / Говнокод #4440

    −111

    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
    def get_line_from_file(path, line)
      result = nil
    
      File.open(path, "r") do |f|
        while line > 0
          line -= 1
          result = f.gets
        end
      end
    
      return result
    end
    
    get_line_from_file("/tmp/foo.txt", 20)

    (с) stackoverflow.com

    Nakilon, 25 Октября 2010

    Комментарии (18)
  5. Java / Говнокод #4430

    +144

    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
    class  JNewConnectionPanel extends JPanel {
    
     public JNewConnectionPanel() {
        this(true, false);
      }
    
      public JNewConnectionPanel(final boolean ok, final boolean cancel) {
        // ...
        if (ok) {
          // ...
        }
        if (cancel) {
          // ...
        }
        // ...
      }
    
     // ...
    }

    продолжаю макакакодить = )

    Lure Of Chaos, 23 Октября 2010

    Комментарии (18)
  6. Pascal / Говнокод #4403

    +97

    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
    Program zadacha; 
    var 
       i,chislo,x,y,m,n:integer; 
    begin 
       while i<1 do begin 
       for x:=0 to chislo do begin 
       for y:=0 to chislo do begin 
       for m:=0 to chislo do begin 
       for n:=0 to chislo do begin 
       if (chislo=x*x*x+y*y*y) and (chislo=m*m*m+n*n*n) and (x<>m) and (x<>y) and (y<>m) and (y<>n) then i:=1 else chislo:=chislo+1; 
       end; 
       end; 
       end; 
       end; 
       end; 
       Writeln(chislo); 
    end.

    Вот так находят "минимальное натуральное число представимое двумя различными способами в виде суммы кубов двух натуральных чисел"

    kolhoz, 20 Октября 2010

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

    +172

    1. 1
    <td><?="ID"?>:</td>

    Пример из документации Bitrix
    http://dev.1c-bitrix.ru/api_help/main/general/admin.section/classes/cadminfilter

    Rpsl, 18 Октября 2010

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

    +122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    List<String> el=parseList();
    		Theme th=new Theme(id);
    
    		th.setScore=Integer.parseInt(el.get(1));
    		th.setComments=Integer.parseInt(el.get(2));
    		th.setAuthor=el.get(3);
    		th.setVisitors=Integer.parseInt(el.get(4));
    		th.setVisitorsLastWeek=Integer.parseInt(el.get(5));
    		th.eMail=el.get(5);
    		return th;

    3.14159265, 12 Октября 2010

    Комментарии (18)
  9. Куча / Говнокод #4247

    +134

    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
    <p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>
    	<p class="MsoNormal" align="center" style="text-align: center; margin-left: 10px; margin-right: 5px; margin-top: 0; margin-bottom: 0">&nbsp;</p>

    Гиппер текст! :)
    http://www.uae-embassy.ru/rco01.htm.
    посольство то же...

    Alfred, 14 Сентября 2010

    Комментарии (18)
  10. SQL / Говнокод #4205

    −128

    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
    CREATE TABLE IF NOT EXISTS `ls_user` (
      `user_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `user_login` varchar(30) NOT NULL,
      `user_password` varchar(50) NOT NULL,
      `user_mail` varchar(50) NOT NULL,
      `user_skill` float(9,3) unsigned NOT NULL DEFAULT '0.000',
      `user_date_register` datetime NOT NULL,
      `user_date_activate` datetime DEFAULT NULL,
      `user_date_comment_last` datetime DEFAULT NULL,
      `user_ip_register` varchar(20) NOT NULL,
      `user_rating` float(9,3) NOT NULL DEFAULT '0.000',
      `user_count_vote` int(11) unsigned NOT NULL DEFAULT '0',
      `user_activate` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `user_activate_key` varchar(32) DEFAULT NULL,
      `user_profile_name` varchar(50) DEFAULT NULL,
      `user_profile_sex` enum('man','woman','other') NOT NULL DEFAULT 'other',
      `user_profile_country` varchar(30) DEFAULT NULL,
      `user_profile_region` varchar(30) DEFAULT NULL,
      `user_profile_city` varchar(30) DEFAULT NULL,
      `user_profile_birthday` datetime DEFAULT NULL,
      `user_profile_site` varchar(200) DEFAULT NULL,
      `user_profile_site_name` varchar(50) DEFAULT NULL,
      `user_profile_icq` bigint(20) unsigned DEFAULT NULL,
      `user_profile_about` text,
      `user_profile_date` datetime DEFAULT NULL,
      `user_profile_avatar` varchar(250) DEFAULT NULL,
      `user_profile_foto` varchar(250) DEFAULT NULL,
      `user_settings_notice_new_topic` tinyint(1) NOT NULL DEFAULT '1',
      `user_settings_notice_new_comment` tinyint(1) NOT NULL DEFAULT '1',
      `user_settings_notice_new_talk` tinyint(1) NOT NULL DEFAULT '1',
      `user_settings_notice_reply_comment` tinyint(1) NOT NULL DEFAULT '1',
      `user_settings_notice_new_friend` tinyint(1) NOT NULL DEFAULT '1',
      PRIMARY KEY (`user_id`),
      UNIQUE KEY `user_login` (`user_login`),
      UNIQUE KEY `user_mail` (`user_mail`),
      KEY `user_activate_key` (`user_activate_key`),
      KEY `user_activate` (`user_activate`),
      KEY `user_rating` (`user_rating`),
      KEY `user_profile_sex` (`user_profile_sex`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
    [/code]
    очень актуально смотрится эта таблица с приведённой выше. очень умно сделать таблицу "топик-стартер" и не выделить отдельно профиль пользователя. что чаще используется в выборке? =)
    про миллионы пользователей и лайвстрит - не смешите, не верю (с)
    загнётся до прихода в БД

    дополнение к http://govnokod.ru/4203
    выделил отдельным гауно-кодом из-за того, что комично смотрится вместе с указанной выше таблицей. ну и ограничение длины комментов есть. ярые искатели оптимизаций видимо идут мимо. очень актуально смотрится эта таблица с приведённой выше. очень умно сделать таблицу админов в один колумн и не выделить отдельно профиль пользователя. что чаще используется в выборке? =)

    hybroid, 09 Сентября 2010

    Комментарии (18)
  11. PHP / Говнокод #4109

    +144

    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
    <?php
    
    class Event {
        private static $_instance = NULL;
        protected $_events_pool = array();
    
        public static function getInstance() {
            if (self::$_instance === NULL) {
                $class = __CLASS__;
                self::$_instance = new $class;
            }
            
            return self::$_instance;
        }
    
        private function __construct() { }
    
        public function connect($event, $callback, array $params = null) {
            $this->_events_pool[$event] = array(
                'callback'	=>	$callback,
                'params'	=>	$params,
            );
            
            return $this;
        }
    
        public function clear($event = NULL) {
            if ($event === NULL) {
                $this->_events_pool = array();
            } else {
                foreach ($this->_events_pool as $id => $_event) {
                     if ($_event['event'] === $event) {
                        $this->_events_pool[$id] = NULL;
                     }
                }
            }
        }
    
        public function emit($events = NULL) {
            if ($events === NULL) {
                $events = array_keys($this->_events_pool);
            } else {
                $events = (is_array($events)) ? $events : array($events);
            }
            
            foreach ($events as $event) {
                foreach ($this->_events_pool as $id => $item) {
                     if ($id === $event) {
                        $this->call($this->_events_pool[$id]['callback']);
                     }
                }
            }
        }
    
        protected function call($class_name, $method_name = NULL, array $params = array(), array $class_params = array()) {	
            $_method = ($method_name === NULL) ? $class_name : array($class_name, $method_name);
            call_user_func_array($_method, $params);
        }
    }

    nergal, 26 Августа 2010

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