{"id":1275,"date":"2018-08-07T16:57:41","date_gmt":"2018-08-07T16:57:41","guid":{"rendered":"http:\/\/sdi.thoughtstorms.info\/?p=1275"},"modified":"2018-08-07T16:57:41","modified_gmt":"2018-08-07T16:57:41","slug":"a-replacement-for-php","status":"publish","type":"post","link":"https:\/\/sdi.thoughtstorms.info\/?p=1275","title":{"rendered":"A Replacement for PHP"},"content":{"rendered":"<p>I <a href=\"https:\/\/www.quora.com\/If-you-could-design-a-new-PHP-today-that-is-a-language-for-light-weight-web-apps-oriented-around-pages-and-always-resident-on-the-server-but-with-a-new-better-syntax-and-semantics-not-PHPs-which-were-based-on-Perl\">asked Quora<\/a> for ideas for how a replacement PHP might look.<br \/>\nOn the whole people are not enthusiastic. Alexander Tchitchigin had an interesting answer, but which focused on the basic theme of &#8220;once we move away from PHP&#8217;s weaknesses, we might as well use any language.<br \/>\nWhich prompted me to write this comment elaborating what I was interested in. Plus some ideas of my own.<br \/>\nI agree that there are downsides to \u201cembedded in HTML\u201d.<br \/>\nBut I think we can also see various what I call \u201cpendulums\u201d in computer science. For example between centralization and decentralization. Centralization gives you economies of scale, eliminates redundancy and makes it easier to see the wood for the trees. Decentralization makes it easier to modularize (or divide and conquer), easier to test and find bugs, easier to scale, easier to improve individual modules etc.<br \/>\nThe pendulum oscillates because whenever one of these principles becomes more dominant, everyone starts to feel the pain and see the attraction of the other pole. And then stories start proliferating of the virtues of shifting the other way. Once everyone does, of course, there\u2019s a pull back to the first way again. And so the pendulum continues to swing.<br \/>\nRight now I\u2019m seeing this centralized \/ decentralized tension in ClojureScript web-frameworks. Comparing using Reagent directly with devcards vs. using Re-frame. Trying to decide whether the convenience of the modularity of keeping state decentralized in individual reagent components and being able to use devcards, outweighs the extra transparency of centralizing state in the re-frame db.<br \/>\nNow I think this thing about \u201cMVC vs. templates with code\u201d is another pendulum rather than an absolute principle.<br \/>\nAt the end of the day, HTML is the data-structure for the application\u2019s GUI. And the GUI data-structure does need to be fairly tightly integrated with the code. It doesn\u2019t make sense to try to decouple them too much. You need a button attached to a handler attached to some transformation in your business logic. There\u2019s no point trying to keep these things apart. A button without functionality makes no sense. Nor does functionality that can\u2019t be accessed through the UI.<br \/>\nI\u2019m now using Hiccup to generate HTML. And the place to do it is obviously tightly integrated with the actual functionality of the app in the code itself.<br \/>\nYes, there are still some MVCish intuitions at work. But I don\u2019t need or want a language to try to hard enforce that separation between UI and functionality either in separate files or with separate <a href=\"http:\/\/thoughtstorms.info\/view\/DecompositionByLanguageIsProbablyAModularityMistake\">languages<\/a>, when a simple DSL in the main programming language is sufficient.<br \/>\nBut when you look at a Reagent (ie. React) component it\u2019s basically a Huccup template with some extra code in it.<br \/>\nNow the brilliance of PHP, the reason it\u2019s so popular is that :<br \/>\na) it\u2019s just there, pretty much always.<br \/>\nb) it simplifies simple sites considerably by automatically mapping the routing onto the directory structure of the file-system. There are many cases when that is fine. Why should I have to hand code a whole layer of routing inside my code when the file system already provides me with a logical hierarchical layout?<br \/>\nI think there\u2019s still value in the \u201cmap files to pages\u201d part of PHP. And that\u2019s what I\u2019d expect a \u201cnew PHP\u201d to keep. Along with the \u201cavailable everywhere\u201d bit.<br \/>\nOf course, how it might look, might be more like Hiccup, a light-weight DSL rather than the verbosity of HTML. With each file implicitly mapped to a React component. Perhaps something like I started describing here : <a href=\"https:\/\/www.quora.com\/Whats-the-best-programming-language-for-applications-and-GUIs\/answer\/Phil-Jones\">Phil Jones&#8217; answer to What&#8217;s the best programming language for applications and GUIs?<\/a><br \/>\nIn that other answer, I talk about what I found interesting in <a href=\"http:\/\/witheve.com\/philosophy\/\">Eve<\/a> : the event-handling  within the language through &#8220;when&#8221; clauses and an implicit underlying data-structure.<br \/>\nAnd I tried to sketch what a language that brought events to Hiccup might look like :<br \/>\n<code> <\/p>\n<pre>\n    (defcomponent click-counter\n    \t{:localstate ['counter 0]\n         :when (on-click \"the-button\") #(reset! counter (+ @counter 1))\n    \t :view\n    \t  [:div\n    \t     [:p \"Counter clicked \" @counter \" times\"]\n             [:button {:id \"the-button\"} \"Click Me\"]\n          ]\n        }\n    )\n<\/pre>\n<p><\/code><br \/>\nMany frameworks encourage you to put components etc. in different files and directories anyway. Why not make this &#8220;official&#8221; in the same way that Python makes indentation official. And use the directory structure to infer the program structure?<br \/>\nA powerful modern language with the easy accessibility defaults of PHP would be a powerful combination.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I asked Quora for ideas for how a replacement PHP might look. On the whole people are not enthusiastic. Alexander Tchitchigin had an interesting answer, but which focused on the basic theme of &#8220;once we move away from PHP&#8217;s weaknesses, we might as well use any language. Which prompted me to write this comment elaborating [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[67,136,340,495],"class_list":["post-1275","post","type-post","status-publish","format-standard","hentry","category-opinion","tag-clojurescript","tag-eve-lang","tag-php","tag-web-frameworks"],"_links":{"self":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/1275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1275"}],"version-history":[{"count":0,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/1275\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}