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

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

    +19

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <?php
    function word_filter($str) {
    	$filtered = '';
    	for ($i = 0; $i <= strlen($str) - 1; $i++) {
    		$char = substr($str, $i, 1);
    		if (ctype_alpha($char)) {
    			$filtered .= $char;
    		}
    	}
    	return $filtered;
    }

    как делают дебилы: $i <= strlen($str) - 1;
    кто знает, так - $j = strlen($str), $i < $j

    guest, 01 Января 2009

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

    +18.7

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $path = "a/b/c/d";
    $sections = array_reverse (explode ("/", $path));
    $sql = "SELECT `t1`.`id` FROM ";
    for ($i = 1; $i <= count ($sections); $i ++)
      $from_tables[] = "`test` `t".$i."`";
    $sql = $sql.implode (", ", $from_tables);
    $sql .= " WHERE ";
    for ($i = 1; $i < count ($sections); $i ++)
      $sql .= "`t".$i."`.`parent_id` = `t".($i+1)."`.`id` AND `t".$i."`.`name` = '".$sections[$i-1]."' AND";
    $sql .= " `t".count ($sections)."`.`parent_id` = '0' AND `t".count ($sections)."`.`name` = '".$sections[count($sections)-1]."'";
    echo $sql;

    guest, 20 Января 2009

    Комментарии (1)
  4. Java / Говнокод #94

    +18.5

    1. 1
    2. 2
    3. 3
    if (true) {
      // Something
    }

    Уже два года, как девушка закончила универ...

    guest, 10 Декабря 2008

    Комментарии (13)
  5. PHP / Говнокод #437

    +18.4

    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
    function convert_code_tag_for_email($text = "", $lang=false)
    {
    	global $MESS;
    	if (strlen($text)<=0) return;
    	if($lang===false) $lang = LANGUAGE_ID;
    	$text = stripslashes($text);
    	$text = preg_replace("#<#", "&lt;", $text);
    	$text = preg_replace("#>#", "&gt;", $text);
    	$text = preg_replace("#^(.*?)$#", "   \\1", $text);
    	$OLD_MESS = $MESS;
    	$MESS = array();
    	include($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/lang/".$lang."/tools.php");
    	$s1 = "--------------- ".$MESS["MAIN_CODE_S"]." -------------------";
    	$MESS = $OLD_MESS;
    	$s2 = str_repeat("-",strlen($s1));
    	$text = "\n\n>".$s1."\n".$text."\n>".$s2."\n\n";
    	return $text;
    }

    говнобитрикс

    guest, 22 Января 2009

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

    +18.3

    1. 1
    2. 2
    3. 3
    4. 4
    while(0<1)
    {
      ...
    }

    В универе встречал такой вот бесконечный цикл

    shurikroger, 12 Августа 2009

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

    +18.3

    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
    MyObject a;
    switch(id)
    {
    case id_1:
    ....
    break;
    
    case id_2:
    break;
    
    case id_3:
    MyObject a;
    a = value;
    break;
    }
    
    res = a;

    псевдо код моей ошибки(((

    guest, 12 Января 2009

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

    +18.3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if( strncmp("ERROR: Unable to service request",msg.data, strlen("Unable to service request")) == 0 )
        return 1;
     if( strncmp("ERROR: (201) Unable to service request",msg.data, strlen("(201) Unable to service request")) == 0 )
        return 1;
     if( strncmp("ОШИБКА: (201) Невозможно обработать запрос.",msg.data, strlen("(201) Невозможно обработать запрос.")) == 0 )
        return 1;
     if( strncmp("ERROR: (201) Невозможно обработать запрос",msg.data, strlen("(201) Невозможно обработать запрос.")) == 0 )
       return 1;

    guest, 30 Декабря 2008

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

    +18.2

    1. 1
    2. 2
    ProfileManager* man = Application::GetProfileManager();
    		_DESIRE(man);	//гм. "Желать мужика". Ужос какой. Это не я написал, если чо. Это оно само

    Вот в коде наткнулся, улыбнуло

    ich, 13 Августа 2009

    Комментарии (2)
  10. C++ / Говнокод #16271

    +18

    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
    #include <iostream>
    #include <memory>
    #include <mutex>
    #include <condition_variable>
    #include <atomic>
    
    
    typedef ::std::unique_lock<::std::mutex> TLock;
    
    using namespace std;
    template<typename T>
    class TQueueElement
    {
    public:
    	T _data;
    	std::shared_ptr<TQueueElement<T> > _prev;
    	mutable ::std::mutex _lockElem;
    
    public:
    	TQueueElement(T data):_data(data),_prev(nullptr){};
    	virtual ~TQueueElement(){};
    
    
    };
    
    template<typename T>
    class TQueue
    {
    private:
    	mutable ::std::mutex _lockHead;
    	mutable ::std::mutex _lockTail;
    	::std::condition_variable _pushToQueue;
    	std::atomic<bool> _isEmpty;
    	std::shared_ptr<TQueueElement<T> > _tail;
    	std::shared_ptr<TQueueElement<T> > _head;
    
    public:
    	TQueue():_lockHead(),_isEmpty(true){};
    	virtual ~TQueue(){};
    
    ///получаем элемент из очереди
    	T pop()
    	{
    		TLock lock(_lockTail);//блокируем все получения из очереди
    		if (_tail==nullptr) 
    			{_isEmpty=true; _pushToQueue.wait(lock,[this](){return !_isEmpty;});} //если очередь пуста ожидаем пока в ней чтото появиться 
    		{
    			TLock lockTail(_tail->_lockElem); //блокируем последний элемент в очереди возможно к нему попробуют обратиться во время запихивания в очередь
    			auto data=_tail->_data;
    			_tail=_tail->_prev;
    			return data;
    		}
    		
    	}
    
    	void push(T data)
    	{
    		auto el=std::shared_ptr<TQueueElement<T> >(new TQueueElement<T>(data));//заранее создаем элемент очереди 
    		TLock lock(_lockHead);
    		if (_isEmpty)//если очередь пуста говорим что наш элемент пока первый и последний
    		{
    			_head=el;
    			_tail=el;
    			_isEmpty=false;
    			_pushToQueue.notify_all();
    		}else//если очередь не пуста 
    		{
    			{
    				TLock lockHead(_head->_lockElem); //блокируем голову от возможного обращения с хвоста
    				_head->_prev=el; //выставляем ссылку на новую голову у старой
    			}
    			_head=el;//выставляем новую голову
    		}
    	}
    
    
    	
    };
    
    
    int main() {
    	TQueue<int> q;
    	q.push(7);
    	q.pop();
    	// your code goes here
    	return 0;
    }

    https://ideone.com/uGX56M
    Ничего не забыл ? Пытался написать очередь для межпоточной синхронизации.

    IKing, 02 Июля 2014

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

    +18

    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
    template <typename T>
      struct canref {
        struct yes { uint8_t bytes[1]; };
        struct no  { uint8_t bytes[2]; };
        template <typename U>    static yes test(U*p);
        template <typename U>    static no  test(...);
        static const bool value = sizeof(test<T>(NULL)) == sizeof(yes);
      };
      template <typename T, int N, bool CanRef=canref<T>::value>
      class array; 
      // class for all types
      template <typename T, int N>
      class array <T,N,true>
      {
        struct Bytes
        {
          uint8_t bytes[sizeof(T)];
        };
        struct TStruct
        {
          T t;
          TStruct(T t):t(t){}
        };
    
        Bytes elements[N];
        int count;
        void copy_ctor (int index, const T& t)
        {
          new (&((*this)[index])) T(t);      
        }
        void copy (int index, const T& t)
        {
          (*this)[index] = t;
        }
    
        void dtor (int index)
        {
          (*this)[index].~T();
        }
      public:
        array () : count(0) {}
    
        ~array () 
        {
          resize(0);
        }
        T& operator [] (int index) 
        {
          assert (index>=0 && index<count);      
          return ((TStruct*)(&elements[index]))->t;
        }
        const T& operator [] (int index) const 
        {
          assert (index>=0 && index<count);      
          return ((TStruct*)(&elements[index]))->t;
        }
        template <int M>
        array (const array<T,M> &a)
        {
          assert(a.count<=N);
          count = a.count;
          for (int i=0; i<count; ++i)
            copyctor(i, a[i]);
        }
        template <int M>
        array& operator = (const array<T,M> &a)
        {
          if (this != &a)
          {
            if (count>a.count)
            {
              for (int i=0;       i<a.count; ++i) copy(i, a[i]);
              for (int i=a.count; i<count;   ++i) dtor(i);
              count = a.count;
            } else
            {
              assert(a.count<=N);
              int ocount = count;
              count = a.count;
              for (int i=0;      i<ocount; ++i) copy(i, a[i]);
              for (int i=ocount; i<count;  ++i) copy_ctor(i, a[i]);
            }
          }
        }
        int size() 
        {
          return count;
        }

    Скоро даже сратору станет очевидно откуда это.

    LispGovno, 10 Января 2014

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