1. 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

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

    +8

    1. 1
    Может кто знает, как работать с методом Table<TEntity>.Attach? Пробовал использовать его по разному, но результат получается один и тот же - Exception.

    Serega9I, 28 Июля 2016

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

    +1

    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
    #include <iostream>
    #include <tuple>
    using namespace std;
    
    template<typename T, typename T0, typename T1, typename ...Args>
    void PrintStruct(const tuple<T0 T::*, T1 T::*, Args T::*...>& members, const T& val)
    {
    	cout << val.*std::get<0>(members) << endl;
    	PrintStruct(members._Get_rest(), val);
    }
    
    template<typename T, typename T0>
    void PrintStruct(const tuple<T0 T::*>& members, const T& val)
    {
    	cout << val.*std::get<0>(members) << endl;
    }
    
    struct MyStruct
    {
    	int x;
    	float y;
    
    	static const tuple<decltype(&MyStruct::x), decltype(&MyStruct::y)> Members;
    };
    
    const tuple<int MyStruct::*, float MyStruct::*> MyStruct::Members = std::make_tuple(&MyStruct::x, &MyStruct::y);
    
    int main()
    {
    	MyStruct str = {123, 3.14159f};
    	PrintStruct(MyStruct::Members, str);
    	return 0;
    }

    Пытался понять, почему мой код не компилится в 2013 студии, и быстренько накатал этот минимальный пример. Но вышел облом - он почему-то компилится, в отличие от моей реальной либы со схожими шаблонными крестоконструкциями.

    gammaker, 27 Июля 2016

    Комментарии (105)
  4. 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)
  5. C++ / Говнокод #20438

    +8

    1. 1
    2. 2
    const
    #include "file.xpm"

    У чувака в файле file.xpm объявлен массив static char * icon_xpm [] = { "..", "..", ... } и он не может заинклудить его в плюсовый код. Вот такой воркараунд ему предложили.
    https://www.linux.org.ru/forum/development/10400992?cid=10406949

    kurwa-nextgen, 27 Июля 2016

    Комментарии (13)
  6. 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)
  7. PHP / Говнокод #20435

    +1

    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
    static function saveoprosform_ajax()
    {
        global $DB, $USER;
        $task_id = $_REQUEST["task_id"];
        $qlist = $_REQUEST["qlist"];
    
        $sql = "DELETE FROM `tickets_qc_results` WHERE `task_id`=" . $DB->F($task_id) . ";";
        $DB->query($sql);
        $DB->free();
    
        if ($task_id && $qlist) {
            // другой говнокод
            $sql = "INSERT INTO `tickets_qc_results`...';
            $DB->query($sql);
        } else {
            $ret["error"] = "Недостаточно данных для выполнения операции!";
        }
        echo json_encode($ret);
        return false;
    }

    Сначала удаляем, потом проверяем by ©senior shaurma developer

    pahhan, 27 Июля 2016

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

    +3

    1. 1
    Я упал

    Xyj, 26 Июля 2016

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

    0

    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
    /**
         * Sets the user in the token.
         *
         * The user can be a UserInterface instance, or an object implementing
         * a __toString method or the username as a regular string.
         *
         * @param string|object $user The user
         *
         * @throws \InvalidArgumentException
         */
        public function setUser($user)
        {
            if (!($user instanceof UserInterface || (is_object($user) && method_exists($user, '__toString')) || is_string($user))) {
                throw new \InvalidArgumentException('$user must be an instanceof UserInterface, an object implementing a __toString method, or a primitive string.');
            }
            if (null === $this->user) {
                $changed = false;
            } elseif ($this->user instanceof UserInterface) {
                if (!$user instanceof UserInterface) {
                    $changed = true;
                } else {
                    $changed = $this->hasUserChanged($user);
                }
            } elseif ($user instanceof UserInterface) {
                $changed = true;
            } else {
                $changed = (string) $this->user !== (string) $user;
            }
            if ($changed) {
                $this->setAuthenticated(false);
            }
            $this->user = $user;
        }

    https://github.com/symfony/security-core/blob/master/Authentication/Token/AbstractToken.php#L93

    craaazy19, 26 Июля 2016

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

    +5

    1. 1
    2. 2
    3. 3
    4. 4
    function is_assoc( $array ) {
    
    	return is_array($array) && substr( json_encode($array), 0, 1 ) == '{';
    }

    bot, 26 Июля 2016

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