1. PHP / Говнокод #23942

    −4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if ($memberInfo['member_profile_image'] != ''):
                                                $memberInfo['photoCount'] = $memberInfo['photoCount'] ;
                                            else:
                                            	$memberInfo['photoCount'] = $memberInfo['photoCount'];
                                                
                                            endif;

    6 строчек кода, а этот код не делает ничего. От слова совсем

    gorsash, 16 Марта 2018

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

    −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
    public function syncStock() {
            $locked = file_exists(__DIR__ . '/lock/gk_sync_stock');
    
            if ($locked) {
                $this->logger->log("Attempt to sync locked stock");
                return;
            }
    
            file_put_contents(__DIR__ . '/lock/gk_sync_stock', current_time('mysql'));
    
            $changed = $this->_syncStock();
    
            unlink(__DIR__ . '/lock/gk_sync_stock');
    
            $this->logger->log("Sync stock complete, $changed changed");
        }

    Тут может произойти дедлок, или ни один из синхронных запросов не выполнится?

    inho, 16 Марта 2018

    Комментарии (35)
  3. Python / Говнокод #23939

    −2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    assert exec("from my_runtime_analyze_lib import do_amazing_magic") or True
    
    
    if __name__ == '__main__':
        do_smth()
        assert do_amazing_magic()
        do_smth_else()

    Как вхерачить в код любую ересь для dev окружения, а потом отключить на продакшене. Только не забыть бы на проде при запуске флаг оптимизации.

    intestinalbrain, 16 Марта 2018

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    Antony Polukhin
     in 
    pro.cxx
    Кстати, в EWG одобрили constexpr контейнеры http://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0784r1.html
    так что есть все шансы к С++20 писать:
    constexpr std::string result = foo();
    t.me/ProCxx
    /184343
    Mar 16 at 10:47

    Library pragmatism

    Current implementations of standard libraries sometimes perform various raw storage operations through interfaces other than the standard allocator and allocator traits. That may make it difficult to make the associated components usable in constexpr components. Based on a cursory examination of current practices, we therefore propose to start only with the requirement that the container templates in the [containers] clause be usable in constexpr evaluation, when instantiated over literal types and the default allocator. In particular, this excludes std::string, std::variant, and various other allocating components. Again, it is our hope we will be able to extend support to more components in the future.

    With regards to the default allocator and allocator traits implementation, the majority of the work is envisioned in the constexpr evaluator: It will recognize those specific components and implement their members directly (without necessarily regarding the library definition).
    We might, however, consider decorating the class members with the constexpr keyword. Also, some implementations provide extra members in these class templates (such as libc++'s allocator_traits<A>::__construct_forward ) that perform non-constexpr-friendly operations (memcpy, in particular). Lifting such members to standard status would help interoperability between library and compiler implementations.

    j123123, 16 Марта 2018

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

    −5

    1. 1
    2. 2
    3. 3
    Внимание!
    Сегодня день числа Пи.
    Давайте все дружно поздравим 3.14159265дара 14 марта в 1:59:27

    inho, 14 Марта 2018

    Комментарии (12)
  6. Python / Говнокод #23921

    +2

    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
    Pyhton 2:
    >>> (2**54/1) + 10 - 10 == 2**54
    True
    
    >>> (2**64/1) + 10  == 2**64
    False
    
    Pyhton 3:
    
    >>> (2**54/1) + 10 - 10 == 2**54
    False
    
    >>> (2**64/1) + 10  == 2**64
    True

    Pyhton 2: https://ideone.com/iqwl8L
    Pyhton 3: https://ideone.com/ltG9Fq

    Ну охуеть теперь.
    x + 10 - 10 != x в общем случае - это норма?
    Я всё понимаю - тяжёлое детство, инты, прибитые к железу, но на кой чёрт в современных интерпретируемых языках такое говнище?

    3.14159265, 13 Марта 2018

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

    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
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    public function insert(array $data)
    {
        $hstoreData = array();
        if (isset($data['description'])) {
            $hstoreData['description'] = $data['description'];
            unset($data['description']);
        }
        if (isset($data['developer'])) {
            $hstoreData['developer'] = $data['developer'];
            unset($data['developer']);
        }
        if (isset($data['localizer'])) {
            $hstoreData['localizer'] = $data['localizer'];
            unset($data['localizer']);
        }
        if (isset($data['gameplay_video'])) {
            $hstoreData['gameplay_video'] = $data['gameplay_video'];
            unset($data['gameplay_video']);
        }
        if (isset($data['news_community_id'])) {
            $hstoreData['news_community_id'] = $data['news_community_id'];
            unset($data['news_community_id']);
        }
        if (isset($data['bg_color'])) {
            $hstoreData['bg_color'] = $data['bg_color'];
            unset($data['bg_color']);
        }
        if (isset($data['bg_image'])) {
            $hstoreData['bg_image'] = $data['bg_image'];
            unset($data['bg_image']);
        }
        if (isset($data['bg_link'])) {
            $hstoreData['bg_link'] = $data['bg_link'];
            unset($data['bg_link']);
        }
        $result = parent::insert($data);
        $this->updateByID($result, $hstoreData);
        return $result;
    }

    Это зачем, интересно?

    vistefan, 13 Марта 2018

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

    +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
    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
    #!/usr/bin/env escript
    %% -*- erlang -*-
    %%! -smp enable -debug verbose
    
    -include_lib("xmerl/include/xmerl.hrl").
    
    -export([main/1, install_mod/1]).
    
    -record(mod_info, { name  :: string()
                      , links :: [{file:filepath(), file:filepath()}]
                      }).
    
    main(Args) ->
        [ModeDir, GameDir] = Args,
        VirtualInstall = filename:absname(ModeDir ++ "/VirtualInstall/"),
        RealPath = filename:absname(GameDir),
        VirtualModCfg = VirtualInstall ++ "/VirtualModConfig.xml",
        io:format( "Mode dir: ~p~n"
                   "Install dir: ~p~n"
                   "Current dir: ~p~n"
                 , [VirtualInstall, RealPath, element(2, file:get_cwd())]),
        {Doc, []} = xmerl_scan:file(VirtualModCfg),
        Mods = get_mods(VirtualInstall, RealPath, Doc),
        [install_mod(I) || I <- Mods],
        ok.
    
    get_mods(VirtPath, RealPath, Doc) ->
        [ #mod_info
              { name  = xpath("/modInfo/@modName", Mod)
              , links = get_links(VirtPath, RealPath, Mod)
              }
          || Mod <- xmerl_xpath:string( "/virtualModActivator/modList/modInfo"
                                      , Doc)].
    
    get_links(VirtPath, RealPath, Doc) ->
        [{ filename:absname( unixify(xpath("/fileLink/@realPath", FL))
                           , VirtPath)
         , filename:absname( unixify(xpath("/fileLink/@virtualPath", FL))
                           , RealPath)
         }
         || FL <- xmerl_xpath:string( "//fileLink[isActive = 'True']"
                                    , Doc)].
    
    xpath(Query, Doc) ->
        case xmerl_xpath:string(Query, Doc) of
            [#xmlAttribute{value = Val}] ->
                Val
        end.
    
    unixify(Path) ->
        lists:map(
          fun($\\) -> $/;
             (A)   -> A
          end,
          Path).
    
    install_mod(#mod_info{name = Name, links = Links}) ->
        io:format("Installing ~s...~n", [Name]),
        lists:foreach(
          fun({From, To}) ->
                  filelib:ensure_dir(To),
                  file:make_symlink(From, To)
          end,
          Links).

    CHayT, 12 Марта 2018

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

    +6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    https://www.opennet.ru/opennews/art.shtml?num=48234
    
    Создатели редактора кода Atom из компании GitHub развивают новый
    экспериментальный текстовый редактор Xray, который также построен
    с использованием фреймворка Electron, но примечателен тем, что для
    повышения надёжности и производительности ядро редактора с
    реализацией базовой логики написано на языке Rust, интерфейс
    оформлен на JavaScript/CSS с применением фреймворка React, а для
    отрисовки текста применяется WebGL.

    Чем вообще руководствуются люди, делающие IDE из кусков браузера? Нахрена там JavaScript/CSS, нахрена там React? Еще и Rust приплели зачем-то.
    Может это чтоб всякие фронтенд-разрабы возрадовались, потому что теперь их умение писать хуиту на жабаскрипте применимо для написания говноплагинов к этой хуите? А как же бекенд? Пусть дополнительно встроят туда PHP MySQL чтоб никто не ушел обиженным.

    j123123, 11 Марта 2018

    Комментарии (270)
  10. Swift / Говнокод #23907

    +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
    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
    protocol Multi {
        associatedtype T
        associatedtype U
    
        func printSelf()
    }
    
    extension Multi where T == Int, U == Float {
        func printSelf() {
            print("Int & Float!")
        }
    }
    
    extension Multi where T == String, U == Int {
        func printSelf() {
            print("String & Int!")
        }
    }
    
    extension Multi {
        func printSelf() {
            print("Unknown")
        }
    }
    
    class MultiImplementationIntFloat: Multi {
        typealias T = Int
        typealias U = Float
    }
    
    class MultiImplementationStringInt: Multi {
        typealias T = String
        typealias U = Int
    }
    
    class MultiImplementationInvalid: Multi {
        typealias T = Float
        typealias U = String
    }
    
    let m1 = MultiImplementationIntFloat()
    m1.printSelf()
    
    let m2 = MultiImplementationStringInt()
    m2.printSelf()
    
    let m3 = MultiImplementationInvalid()
    m3.printSelf()

    Multimethods в Swift с проверкой в compile-time

    Desktop, 10 Марта 2018

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