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

    −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
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    <ul class="news-list">
    
        <?php
    global $news_list_toc;
    foreach ($news_list_toc as $i => $d) {
        echo <<<NI_ITEM
        <li class="news-list-item">
            <div class="news-list-item-date">
                {$d['date']}
            </div>
            <div class="news-list-item-title">
                <a href="?fetch=news&with=the&id={$i}">{$d['title']}</a>
            </div>
        </li>
    NI_ITEM;
    
        } ?>
    
    </ul>

    Нашел при рефакторинге своего проекта. Чем, чем я думал, когда писал это? У нормальных людей такого органа кажется и нету...

    Показывать на собеседованиях с вопросом "что вам нравится в этом коде?"

    Запостил: Arris, 02 Августа 2018

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

    • Да, разумеется, это html-файл шаблона :)
      Ответить
    • И хуле? Внимания не хватает? Хочешь, чтобы вокруг тебя все раскукарекались, мол, "ах, фигурные скобки, ах, три знака "меньше", куд-кудах"?
      Ответить
    • what is the difference between markup and programming?
      “<?php” and “echo”
      Ответить
      • показать все, что скрытоvanished
        Ответить
      • показать все, что скрытоvanished
        Ответить
      • There is no difference in this particular case:)

        I have strong feeling that view should be UI-agnostic as much, as possible. One may use REST or HTML or PDF to "render" stuff, so you should not have HTML hardcoded into your templaes
        Ответить
        • Name some implementations of this idea
          Ответить
          • Docbook
            Ответить
            • tex?

              I told more about web programming, what is a bright example for html-independent templating. All DSL's and templaters I know only allows programmer to express his thoughts in terms of html tags and subtemplates.
              Ответить
              • It's actually pretty simple to implement this idea. If you have just a semantic description of the document, you can render it in any format you like. You just need a semantic representation. Docbook[1], Dita[2], Scribble[3], Asciidoc[4], Markdown [5] and many more could be such representations. To be honest, even HTML can be such a representation.

                In real life almost nobody cares about this when developing a website. Because when you print something, you don't want to include most of the stuff you usually see on the webpage, so you'll need a customized view of the page anyway. I don't see any problem with having specific templates for different presentations of the same data.

                See also: Pandoc[6]
                [1] https://docbook.org/
                [2] https://dita.xml.org/
                [3] https://docs.racket-lang.org/scribble/
                [4] http://asciidoc.org/
                [5] http://daringfireball.net/projects/markdown/syntax
                [6] https://pandoc.org/
                Ответить
                • I found better way to make footnotes¹ with Compose key.² We could do it just like in a book, that is, surely, highest standard for typographic and readability. This could be made with “^1”, …, “^2” keystrokes.

                  ¹ like this (isn't it pretty?)
                  ² https://en.wikipedia.org/wiki/Compose_key
                  Ответить
                  • Ich weiß, wie man die Compose-Taste benutzt, danke.
                    À bientôt.
                    Ответить
                  • показать все, что скрытоvanished
                    Ответить
                  • \[[0-9]+\] это не сноски же, а пародия на список литераторы.
                    Ответить
                  • > footnotes
                    > highest standard for typographic and readability
                    > like this (isn't it pretty?)

                    Footnotes, references and bibliography items decrease readability. They add extra symbols to read and prevent one from straigthforward reading. One can't focus on reading and has to traversing a book graph.
                    Moving focus point for a reader is like random access reading for a HDD. Sequentional reading is easier and faster.
                    I believe authors should think about their readers' experiences and make the linearest book they can. (e.g. "Learn You a Haskell for Great Good")
                    The only case the graph text structure is appropriate is wiki pages and stackoverflow-like sites for fast googling.
                    Ответить
                    • > Footnotes decrease readability

                      You're not obligated to read footnotes, they just provide additional information that will distract you from the main idea if you inline this information in the main sentence. You don't need to read the footnotes in order to understand the topic.

                      > Sequentional reading is easier and faster.

                      You must be enjoying reading minimized JS files. So sequental, very readable.

                      No, it's not. One huge blob of text is the hardest thing to read and navigate. That's why we have tables of contents, headers, paragraphs and bullets. That's why we build filesystems to use our HDDs. When you have a list of bullets, you can skip through them quickly and understand boundaries of ideas better.


                      The optimal structure really depends on what you read though.
                      • If it's fiction, simple chapters filled with blobs will do just fine.
                      • If it's a man page, you'll use a lot of headers, lists and small paragraphs.
                      • If it's a technical book, you'll have to use a lot references, indices, and a proper table of contents.
                      Ответить
                      • >> Sequentional reading is easier and faster.
                        > No, it's not. One huge blob of text is the hardest thing to read and navigate. That's why we have tables of contents, headers, paragraphs and bullets.
                        > That's why we build filesystems to use our HDDs.

                        Sequentional reading does not require lack of structure. Reading the file you want to read is a typical action.
                        Headers and chapters do increase readability. But they are also printed in a certain order that provides one the ability of reading sequentionally. So one can read arbitrary subsequences.

                        It's bad when the order of printing is not enough. The number of these cases should be decreased.

                        > You're not obligated
                        > If it's a technical book, you'll have to use a lot references
                        A lot of references make it unreadable. It's a torture when the author kindly asks one to turn 100500 pages to see some formulae they could print several times. The book "Learn You a Haskell for Great Good" mentioned above could have a lot of cross references to some code snippets. But they just printed them again that makes the book great.
                        Ответить
                        • References should not affect readability at all. They are additional information, you can ignore it if you don't need it, but you can always appeal to it when you need. Pretty readable linear book with no need to turn pages (it is so hard…) are useful and enjoyable for learning, to not to be bored and to meet some subject you're totally unfamiliar to. In this case if you see some reference, you have no enough experience to decide, if you have to follow link or not. This can be really abusing. Such book don't need to be good-structured and linkable. Simple information is not as reusable as comprehensive information. When you learned something simple, you don't need to return back to learn it again. But when you appeal to some competent information, you can't get it all in your head, and in some cases you should not to. Such information ought to be highly organized and referenced. And sometimes it should not be linear at all. Even if it is a book.
                          Ответить
                          • > When you learned something simple, you don't need to return back to learn it again. But when you appeal to some competent information, you can't get it all in your head, and in some cases you should not to. Such information ought to be highly organized and referenced. And sometimes it should not be linear at all. Even if it is a book.

                            You time is still linear. So you have to choose your personal order if there is no one.
                            There are two ways: to traverse it piece after piece (beginning -> end) and to learn some basics and go deeper and deeper (top -> bottom). The author could choose one of the ways and provide us some default order.
                            The second way is OK for complicated things. 5 minute tutorial + a linear book + a huge highly referenced database for occasional access would be enough. The book could be just an ordered subset of the database.
                            Ответить
                      • P.S. One could say the pieces of knowledge we have cannot be traversed in general.
                        I would like to mention that the numbers we use are 0% of all the numbers having finite representation that in turn are 0% of real numbers. But we still don't reject mathematics.
                        Books are meant to be readable and educating. One should consider going beyond the standards to make reading simpler.
                        Ответить
                    • > The only case the graph text structure is appropriate is wiki pages and stackoverflow-like sites for fast googling.

                      Such things like hyperlinks are never a part of linear text. Nobody reads them. They just interrupt you while reading and you're in good luck if link is something you need, else it is just a mess in the middle of text. Unlike it, list of references gives you linearity of reading and completeness of information at the same time. It also gives you ability to return back later and see all links in common, without of searching it all over the text.

                      A couple of weeks ago here we discussed videos vs. blog-posts, mentioning that videos are hard to link and poorly structured and searchable.

                      > The only case…

                      Probably, you're right, and I think one should make this kind of text. What is more informative, reusable, relevant, searchable and instructive, pretty linear “What a boat-hook)))” or a post full of references combined in list?
                      Ответить
                      • > Unlike it, list of references gives you linearity of reading and completeness of information at the same time.
                        The order of references list results from the order of their appearance in the text. You cannot use either when reading the whole books or when reading only the quoted text.

                        > What is more informative, reusable, relevant, searchable and instructive, pretty linear “What a boat-hook)))” or a post full of references combined in list?
                        I'm sure the first one is better. It's understandable, fast to read, the linearest possible. It's being unambiguous makes it easier to find.
                        Ответить
                    • Тоже не знаю, зачем так делать за пределами печатной литературы
                      Ответить
    • омг, еще один шобланизатор из хередок
      Ответить
      • показать все, что скрытоvanished
        Ответить
        • Откуда тебе знать что хередок существует в куче япов, включая перл и руби? Ты же ничего кроме "PHP" не знаешь.

          зы: была слаба на хередок
          Ответить
          • показать все, что скрытоvanished
            Ответить
            • Разве есть нормальные языки кроме "PHP"?
              Ответить
              • Будем честны - нет. Столкнулся с "Java", и впечатление моё таково, что большего говна я ещё не видел: какие-то "import"-ы, какие-то "context"-ы, какие-то классы и методы, которые я в "PHP" обходил десятой дорогой, какая-то путаница - не знаешь, что откуда вызывается, что к чему относится... Несравнимо с влажненьким процедурненьким кодом "PHP" и "JavaScript", где код действий описывается в той же последовательности, в которой эти действия и выполняются; где нет завихрений, коловращений, подвыпердов...
                Ответить
    • Ну и пусть так. Я не хочу его терять. Не хочу! Не буду! И теперь уже никому не отдам!
      Ответить

    Добавить комментарий