TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

80% of my coding is doing this (or why templates are dead)

15 点作者 StokeMasterJack将近 8 年前

5 条评论

krapp将近 8 年前
XHP templates in Hack wind up being really nice, letting you create composable XML tags, defining attribute types, etc. And they look a lot like JSX, except with extending classes. I suppose that counts as an &quot;internal DSL.&quot;<p><pre><code> &#x2F;&#x2F;&lt;csrf-form&gt;(...)&lt;&#x2F;csrf-form&gt; class :csrf-form extends :x:element { attribute :form; use XHPHelpers; protected function Render(): XHPRoot { $token=get_csrf_token(); return &lt;form&gt; &lt;input type=&quot;hidden&quot; name=&quot;token&quot; value={$token}&#x2F;&gt; {$this-&gt;getChildren()} &lt;&#x2F;form&gt;; } } </code></pre> More boilerplate than Twig, but no string concatenation.
fao_将近 8 年前
<p><pre><code> DSL stands for Domain Specific Language. In our story, the DSL is HTML. An internal DSL refers to the host programming language’s ability to express that DSL using just the host language (with no string building). One could argue that Internal DSLs are not really a separate technique from #2 (Tree Building) and #3 (Templates). In fact, internal DSLs could be described as a less-crappy tree building API. Or as a templating language that is more integral to the host language. But I think the technique is different enough to deserve it’s own category. </code></pre> This person is describing Lisp, and I&#x27;m flummoxed that they do not appear to be aware of Lisp, given that it is an area where it is so strong! I think both Arc and Closure have the ability to describe HTML documents in lists (I can&#x27;t remember if it&#x27;s as s-expressions, or lists of functions).<p>EDIT: I just noticed that they reference Om :) Never mind!
评论 #14872765 未加载
评论 #14871346 未加载
评论 #14875865 未加载
wodeveloper将近 8 年前
&quot;One could argue that Internal DSLs are not really a separate technique from #2 (Tree Building) and #3 (Templates)&quot;<p>JSX doesn&#x27;t strike me as that much different from JSP. It&#x27;s still mixing markup and code together.<p>There&#x27;s another #4. That was Apple&#x27;s WebObjects. WebObjects was unique in that it provided bindings between the two languages. In one file, you have HTML, in another, you have Java. Then in a third, the .WOD file, you had bindings between the two.<p>The HTML was really XHTML with one extra tag, the webobject tag, and it had one name attribute. Nothing new to learn there.<p>&lt;webobject name=&quot;NameFromHTML&quot;&#x2F;&gt;<p>The java file was just a java object that implemented the WOComponent class.<p>public class WOComponentClassName extends WOComponent {...}<p>The WOD bound the two together like<p>NameFromHTML : WOComponentClassName { key1 = value1; }<p>If you needed to reuse a chunk, you could just reference it twice with another &lt;webobject name=&quot;NameFromHTML&quot;&#x2F;&gt;.<p>Then at runtime, the webobjects application read in the html templates, and associated the key with a WOComponent getter&#x2F;setter or field, and the value was either hard coded, or came from the java component as well.<p>HTML templates quickly boiled down to a handful of &lt;webobject&gt; tags. You could express entire, complex pages with just a few tags.<p>Later on, developers with bad habits tried to add in things they were familiar with from other lesser solutions. WebObjects slowly degenerated into something that looked more like JSP with bindings being set inline in the html, executable binding values with OGNL, the whole works. It turned something beautiful and still more advanced than any template language in use today, into your standard template language garbage pile.<p>It&#x27;s fortunate that server side rendering went out of fashion, Apple promptly dropped support, and WebObjects was allowed to die a somewhat dignified death in obscurity.
segmondy将近 8 年前
Ugh, that&#x27;s what lisp solves for, that&#x27;s why folks rave about lisp macros, and prolog solves that too with it&#x27;s DCG.<p>If not using those, don&#x27;t use languages to generate HTML, hand craft it, same with SQL, don&#x27;t use ORMs, hand craft it.
评论 #14875015 未加载
brad0将近 8 年前
&gt; OK. Maybe not 80%. Maybe 50%. It’s hard to say.<p>Saying it&#x27;s 80% in the headline then immediately saying it might be 50% is clickbaity.
评论 #14875881 未加载