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

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

    +54

    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
    // We now have a locale string, but the global locale can be changed by
    // another thread. If we allow this thread's locale to be updated before we're done
    // with this string, it might be freed from under us.
    // Call versions of the wide-to-MB-char conversions that do not update the current thread's
    // locale.
    
    //...
    
    /*
                 * Note that we are using a risky trick here.  We are adding this
                 * locale to an existing threadlocinfo struct, and thus starting
                 * the locale's refcount with the same value as the whole struct.
                 * That means all code which modifies both threadlocinfo::refcount
                 * and threadlocinfo::lc_category[]::refcount in structs that are
                 * potentially shared across threads must make those modifications
                 * under _SETLOCALE_LOCK.  Otherwise, there's a race condition
                 * for some other thread modifying threadlocinfo::refcount after
                 * we load it but before we store it to refcount.
                 */

    MS VS 2013 CRT

    LispGovno, 23 Января 2015

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

    +54

    1. 1
    ((Dialog*)parent)->getSquareStorage()->at(((Dialog*)parent)->getSquareStorage()->size() / 2)->setColor(0,0,0);

    Qt. Я естественно сразу же переписал этот шлак

    artembegood, 15 Января 2015

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

    +54

    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
    // Блок кода с выходом по break
    #define BLOCK for (int _count = 1; _count--;)
    
    bool Result::commit()
    {
    	BLOCK {
    		mysql_query(db->mysql, "BEGIN");
    
    		if (!saveBasePart())
    			break;
    
    		if (getCategory() != NULL) {
    			if (!saveCustomValues())
    				break;
    		}
    
    		mysql_query(db->mysql, "COMMIT");
    		return true;
    	}
    
    	mysql_query(db->mysql, "ROLLBACK");
    	return false;
    }

    hdkeeper, 14 Января 2015

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

    +54

    1. 1
    virtual bool    IsUnlockedAll(){bool temp = false;return temp^temp;};

    Код с боевого проекта. Комментариев не будет.

    DlangGovno, 26 Ноября 2014

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

    +54

    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
    //Given a number, turns on those segments
    //If number == 10, then turn off number
    void lightNumber(int numberToDisplay) {
    
    #define SEGMENT_ON  LOW
    #define SEGMENT_OFF HIGH
    
      switch (numberToDisplay){
    
      case 0:
        digitalWrite(segA, SEGMENT_ON);
        digitalWrite(segB, SEGMENT_ON);
        digitalWrite(segC, SEGMENT_ON);
        digitalWrite(segD, SEGMENT_ON);
        digitalWrite(segE, SEGMENT_ON);
        digitalWrite(segF, SEGMENT_ON);
        digitalWrite(segG, SEGMENT_OFF);
        break;
    
      case 1:
        digitalWrite(segA, SEGMENT_OFF);
        digitalWrite(segB, SEGMENT_ON);
        digitalWrite(segC, SEGMENT_ON);
        digitalWrite(segD, SEGMENT_OFF);
        digitalWrite(segE, SEGMENT_OFF);
        digitalWrite(segF, SEGMENT_OFF);
        digitalWrite(segG, SEGMENT_OFF);
        break;
    
    
    ; и т. д.
    
    
      case 9:
        digitalWrite(segA, SEGMENT_ON);
        digitalWrite(segB, SEGMENT_ON);
        digitalWrite(segC, SEGMENT_ON);
        digitalWrite(segD, SEGMENT_ON);
        digitalWrite(segE, SEGMENT_OFF);
        digitalWrite(segF, SEGMENT_ON);
        digitalWrite(segG, SEGMENT_ON);
        break;
    
      case 10:
        digitalWrite(segA, SEGMENT_OFF);
        digitalWrite(segB, SEGMENT_OFF);
        digitalWrite(segC, SEGMENT_OFF);
        digitalWrite(segD, SEGMENT_OFF);
        digitalWrite(segE, SEGMENT_OFF);
        digitalWrite(segF, SEGMENT_OFF);
        digitalWrite(segG, SEGMENT_OFF);
        break;
      }
    }

    Управление 7-сегментным индикатором для ардуины

    govnokod3r, 25 Октября 2014

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

    +54

    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
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    using namespace std;
     
    int main()
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        long x1, x2, x3;
        cin >> x1 >> x2 >> x3;
        if(x1 == 0 && x2 == 0 && x3 == 0){
            cout << 0 << endl;
            exit(EXIT_SUCCESS);
        }
        (x1 != 0) ? cout << x1 : cout << "";
        (x2 != 0) ? (x2 > 0 && x1 != 0) ? (x2 == 1) ? cout << "+x" : cout << '+' << x2 << 'x' : (x2 == -1) ? cout << "-x" : (x2 == 1) ? cout << 'x' : (x2 == -1) ? cout << "-x" : cout << x2 << 'x' : cout << "";
        (x3 != 0) ? (x3 == 1) ? cout << 'y' : (x3 == -1) ? cout << "-y" : (x2 == 0 && x1 == 0) ? cout << x3 << 'y' :  (x3 > 0) ? (x3 == 1) ? cout << "+y" : cout << '+' << x3 << 'y' : (x3 == -1) ? cout << "-y" : cout << x3 << 'y' : cout << "";
        cout << endl;
        return 0;
    }

    Задача № 277 на acmp.ru. Решил "не писать много кода"

    jyree, 21 Сентября 2014

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

    +54

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    Exchange::Params pars = rawParams;
    for(Exchange::Params::const_iterator i = rawParams.constBegin(); i!= rawParams.constEnd(); i++){
        LOGN() << "Work with " << i.key() << "=" << i.value();
        if(m_specific.contains(i.key())){
            pars[i.key()] =
                (this->*m_specific.value(i.key())) (i.value());     //черная магия :)
        }
    }

    Наследие из большого рабочего проекта.
    Чтобы сохранить ясность ума на весь день решил не пытаться понять что оно делает.

    FlySnake, 08 Сентября 2014

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

    +54

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public function accuire($array = array()) {
            return $this->acquire($array);
        }
    
        public function acquire($array = array()) {

    Spell-master

    jfhs, 25 Января 2013

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

    +54

    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
    <?php
    
        class ArrObj implements ArrayAccess, Countable, Iterator
        {
    
            protected $_data = array();
            protected $_indexes = array();
            protected $_pos = 0;
    
            public function __construct($data = array())
            {
                $this->_data = $data;
            }
    
            public function offsetGet($name)
            {
                if($isset = isset($this->_data[$name])) return $this->_data[$name];
                $this->_data[$name] = new self();
                return $isset ? $this->_data[$name] : null;
            }
    
            public function offsetSet($name, $value)
            {
                if(is_array($value)) $value = new self($value);
                $this->_data[$name] = $value;
                $this->_indexes[] = $name;
                return $value;
            }
    
            public function offsetUnset($name)
            {
                unset($this->_data[$name]);
                $this->_indexes = array_merge(array_diff($this->_indexes, array($name)));
            }
    
            public function offsetExists($name)
            {
                return isset($this->_data[$name]);
            }
    
            public function count()
            {
                return count($this->_data);
            }
    
            public function rewind()
            {
                $this->_pos = 0;
            }
    
            public function current()
            {
                return $this->_data[$this->_indexes[$this->_pos]];
            }
    
            public function key()
            {
                return $this->_indexes[$this->_pos];
            }
    
            public function next()
            {
                ++$this->_pos;
            }
    
            public function valid()
            {
                return isset($this->_indexes[$this->_pos]);
            }
    
        }
    
    ?>

    Sarkian, 18 Января 2013

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

    +54

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    // sys
    if ($flag==1) {
            $rr = implode("</B>, <B>",$nks1)."</B> и <B>".implode("</B>, <B>",$nks2);
    } elseif ($flag==2) {
        $rr = implode("</B>, <B>",$nks1)."</B> и <B>".implode("</B>, <B>",$nks2)."";
    } else {
        $rr = implode("</B>, <B>",$nks1)."</B> и <B>".implode("</B>, <B>",$nks2)."";
    }

    Это нашел в движке одной онлайн игры... Три проверки, но 1 и то же действие... Логика, мать её...

    RickMan, 16 Января 2013

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