Кресты / Говнокод #26946 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
foreach ($files as $n => $f) {
    $new_content = $common.$namespace_begin.$f.$namespace_end;

    $std_methods = array();
    preg_match_all('/std::[a-z_0-9]*/', $new_content, $std_methods);
    $std_methods = array_unique($std_methods[0]);

    $needed_std_headers = array();
    $type_headers = array(
        'std::move' => '',
        'std::vector' => '',
        'std::string' => '',
// [...]
        'std::unordered_set' => 'unordered_set');
    foreach ($type_headers as $type => $header) {
        if (in_array($type, $std_methods)) {
            $std_methods = array_diff($std_methods, array($type));
            if ($header && !in_array($header, $needed_std_headers)) {
                $needed_std_headers[] = $header;
            }
        }
    }

    if (!$std_methods) { // know all needed std headers
        $new_content = preg_replace_callback(
            '/#include <([a-z_]*)>/',
            function ($matches) use ($needed_std_headers) {
                if (in_array($matches[1], $needed_std_headers)) {
                    return $matches[0];
                }
                return '';
            },
            $new_content
        );
    }

Тут вот в https://govnokod.ru/20049 CHayT предлагал использовать «PHP» в качестве препроцессора для «C» — так вот в «Телеграме» совет оценили и решили взять на вооружение.
https://github.com/tdlib/td/blob/master/SplitSource.php

Запостил: gost gost, (Updated )

Комментарии (20) RSS

  • «PHP» олимпиадный — очень редкий сорт говна!
    Ответить
  • По-моему главный багор это то что в с до сих пор нет общепринятого стандарта для генерации доков как где угодно кроме с
    Ответить
    • doxygen? По-моему стандарт де-факто для сишки и няшной.
      Ответить
    • да ладно, питонобляди тоже три варианта имеют.

      У сишечки нету единого стандарта вообще ни у чего кроме языка, даже у кодстайла, потому что слишком разны места, где ее можно встретить
      Ответить
  • Сначала я закрыл нос он вони, но затем увидел в этом своеобразную эстетику декаданса
    $needed_std_headers = array();
            $type_headers = array(
                'std::move' => '',
                'std::vector' => '',
                'std::string' => '',
                'std::uint32_t' => '',
                'std::int32_t' => '',
                'std::int64_t' => '',
                'std::fill' => 'algorithm',
                'std::find' => 'algorithm',
                'std::max' => 'algorithm',
    Ответить
  • Какие-то гнусные, неконсистентные регулярки. Буэээ.
    'PublicDialogType|get_public_dialog_type' => 'PublicDialogType',
    'SecretChatActor' => 'SecretChatActor',
    'secret_chats_manager[_(-][^.]|SecretChatsManager' => 'SecretChatsManager',
    'stickers_manager[_(-][^.]|StickersManager' => 'StickersManager',
    '[>](td_db[(][)]|get_td_db_impl[(])|TdDb[^A-Za-z]' => 'TdDb',
    'TopDialogCategory|get_top_dialog_category' => 'TopDialogCategory',
    'top_dialog_manager[_(-][^.]|TopDialogManager' => 'TopDialogManager',
    'updates_manager[_(-][^.]|UpdatesManager|get_difference[)]' => 'UpdatesManager',
    Ответить
  • Судя по обилию td::this_thread::yield() в коде
    namespace this_thread_pthread {
    void yield() {
      sched_yield();

    Закрадываются нехорошие подозрения.
    bool next() {
        // TODO: find out better strategy
        // TODO: try adaptive backoff
        // TODO: different strategy one core cpu
        // return false;
    
        cnt++;
        if (cnt < 1) {  // 50
          return true;
        } else {
          td::this_thread::yield();
          return cnt < 3;  // 500
        }
    Ответить
    • End result: sched_yield() is basically historical garbage. 
      It's often literally wrong even for the defined usage because times have moved on from that whole "we run one thing at a time" long long ago.
      If your RT system actually has multiple concurrent threads (as opposed to being limited to a dedicated CPU) it's not really all that well-defined even there. But at least there you can still pretend it is.
      
      So what happens? Pretty much every single use of sched_yield() is some random person doing something wrong, and they have added it randomly to their load based on the random timing behavior on their machine.
      They may even have done extensive timings on a benchmark of their load in order to find exactly where they should yield.
      
      And then the system topology changes, and you have a hundred other sched_yield() users that use it for what they tuned things for, and their load behavior is very different indeed...
      
      In other words, if you think your locking should depend on 'sched_yield()', you're simply wrong.


      Послание очень длинное.
      Читать полностью: ==>
      https://www.realworldtech.com/forum/?threadid=189711&curpostid=189752
      Ответить
      • да, елдить треды на вытесняющей многозадачности странно. В жабке тоже есть елд, и он тоже не нужен.

        адский говнокод
        Ответить
  • ебать поехавшие
    '(?<name>[A-Z][A-Za-z]*) : public (Td::ResultHandler|NetActor|Request)|'.
                               '(CREATE_REQUEST|CREATE_NO_ARGS_REQUEST)[(](?<name>[A-Z][A-Za-z]*)|'.
                               '(?<name>complete_pending_preauthentication_requests)|'.
                               '(Up|Down)load[a-zA-Z]*C(?<name>allback)|(up|down)load_[a-z_]*_c(?<name>allback)_|'.
                               '(?<name>lazy_to_json)|'.
                               '(?<name>LogEvent)[^sA]|'.
                               '(?<name>parse)[(]|'.
    Ответить

Добавить комментарий для gost Отменить ответ

Переведи на "PHP", guest!

    А не использовать ли нам bbcode?


    8