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

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

    +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
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    @PostLoad
        protected void initStatus() {
            anState status = null;
            if (isDeleted()) {
                status = anState.S_DELETED;
            } else if (actState != null) {
                if (actState.equals(anState.S_NOT_FILLED)) {
                    status = anState.S_NOT_FILLED;
                } else if (actState.equals(anState.S_FORMED)) {
                    status = anState.S_FORMED;
                } else if (actState.equals(anState.S_SENT) &&
                        (Document != null && Document.getState().equals(DocumentState.SENT))) {
                    status = anState.S_SENT;
                } else if (actState.equals(anState.S_SENT) &&
                        (Document == null ||
                                (Document != null && !Document.getState().equals(DocumentState.SENT)))) {
                    status = anState.S_SENDING;
                } else if (actState.equals(anState.S_CANCELLATION_REQUEST)) {
                    status = anState.S_CANCELLATION_REQUEST;
                } else if (actState.equals(anState.S_CANCELED)) {
                    status = anState.S_CANCELED;
                }
            }
            this.status = status;
        }

    > кстати, валится же в методе

    private boolean isReadonly(anState status) {
    return !status.equals(anState.ACT_FORMED) &&
    !status.equals(anState.ACT_NOT_FILLED);
    }

    > но мы же не знаем, что енумы можно сравнивать и по == (т.к. поля енума - константы), и привычки сравнивать equals на константном выражении тем более не имеем :)

    > facepalm.jpg, словом :)

    Lure Of Chaos, 28 Июля 2016

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $exceptionClass = '\yii\db\Exception';
    foreach ($this->exceptionMap as $error => $class) {
        if (strpos($e->getMessage(), $error) !== false) {
            $exceptionClass = $class;
        }
    }
    ...
    return new $exceptionClass($message, $errorInfo, (int) $e->getCode(), $e);

    Yii <3

    https://github.com/yiisoft/yii2/blob/master/framework/db/Schema.php#L625-L633

    Fike, 27 Июля 2016

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

    +3

    1. 1
    2. 2
    $arParams["SET_TITLE"] = $arParams["SET_TITLE"]!="N";
    $arParams["SET_LAST_MODIFIED"] = $arParams["SET_LAST_MODIFIED"]==="Y";

    news.detail - cтандартный компонент Битрикса

    pgood, 27 Июля 2016

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

    +3

    1. 1
    Я упал

    Xyj, 26 Июля 2016

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

    +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
    18. 18
    19. 19
    20. 20
    21. 21
    #include <iostream>
     
    class A
    {
    public:
        virtual void print(int val = 10) { std::cout << "A" << val; }
    };
     
    class B : public A
    {
    public:
        virtual void print(int val = 20) { std::cout << "B" << val; }
    };
     
    int main()
    {
        B b;
        A& a = b;
        a.print();
        return 0;
    }

    when you see it, you’ll shit bricks

    Tonghost, 26 Июля 2016

    Комментарии (36)
  7. Куча / Говнокод #20415

    +3

    1. 1
    ^[\s\u200c]+|[\s\u200c]+$

    Стековерфло не могут в регулярные выражения или регулярные выражения не могут в простейшую задачу?
    http://stackstatus.net/post/147710624694/outage-postmortem-july-20-2016

    kipar, 23 Июля 2016

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    #include <windows.h>
    int main() {
    	HDC dc = CreateCompatibleDC (NULL);
    	SetLayout (dc, LAYOUT_RTL);
    	ScaleWindowExtEx (dc, -2147483647 - 1, -1, 1, 1, NULL);
    }

    bsod

    laMer007, 22 Июля 2016

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

    +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
    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
    #define __DEBUG
    #ifdef __DEBUG
        #define print_pair(p) do{std::cout << "(" << ((p).first + 1) << ", "\
                                << ((p).second + 1) << ")" << std::endl;}while(0);
    #endif
    
    Graph::result
    Graph::dijkstra (int start)
    {
    #ifdef __DEBUG
        std::cout << "Dijkstra algorithm tracing:" << std::endl;
    #endif
        distances[start] = 0;
        std::set<std::pair<int, int>> q;
        q.insert (std::make_pair(distances[start], start));
        while (!q.empty())
        {
    #ifdef __DEBUG
            std::cout << "top element of a set: ";
            print_pair(*q.begin());
    #endif
            int current = q.begin()->second;
            q.erase(q.begin());
            for (int i = 0; i < adj[current].size(); ++i)
            {
    #ifdef __DEBUG
        std::cout << "current vertex: " << (current + 1);
        std::cout << " ad current state of distances array is: " << std::endl;
        for (auto i: distances)
            std::cout << i << " ";
        std::cout << std::endl;
    #endif
                int to = adj[current][i].second;
                int length = adj[current][i].first;
                // Relaxations
                if (distances[to] > distances[current] + length)
                {
    #ifdef __DEBUG
        std::cout << "relaxation for edge (" << current << ", " << to << ") ";
        std::cout << "with weight " << length << std::endl;
    #endif
                    
                    q.erase(std::make_pair(distances[to], to));
                    distances[to] = distances[current] + length;
                    path[to] = current;
                    q.insert(std::make_pair(distances[to], to));
                }
            }
        }
        // Replace INF by -1
        std::replace (distances.begin(), distances.end(), INF, -1);
        return distances;
    }

    Я у мамы решил подебажить как мыщъх дебажил при помощи отладочной печати. Вот что получилось.

    HiewMorjowie, 18 Июля 2016

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

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    #include <iostream>
    #include <vector>
    using namespace std;														
    
    
    int main() {
    	victor<bull> v = {1,0,1};
    	for(auto&& i : v) //Если удалить один &, то не скомпилируется
    		cout<<i<<endl;
    	return 0;
    }

    http://rextester.com/DBCM68277

    laMer007, 13 Июля 2016

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public function favoriteCount($userId) {
    		$query = $this->db->query("SELECT * FROM ".DB_PREFIX."favorite WHERE customer_id =".$this->db->escape($userId));
    		$rows = $query->rows;
    		return count($rows);
    }

    Opencart.
    Потому что агрегатные функции для слабаков!

    Panda, 13 Июля 2016

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