Expressive syntax vs. view preprocessing: how to strike a balance? #163
Replies: 2 comments 7 replies
-
Having a go at this myself, let me order some existing and hypothetical features from most purist at the top to most pragmatist at the bottom. (I did not put this in the opening post, because any such ordering is imprecise and subjective.)
I would say that 1-9 are essential to not make Mustache harder to use than necessary, while 15-22 are unreasonable. I think the balance is between 12 and 13: dynamic partials are still acceptable, skip syntax is not. As a guiding principle, I would propose that every new feature added to the language should multiply the possibilities but only increment the syntactic complexity and the cost of implementation. In other words, new features that reduce the need for preprocessing are acceptable in principle, but only if high orthogonality is preserved. Given multiple possible solutions for a problem, the most orthogonal option should be chosen. Filters (8) do really well in this regard: they open a million possibilities that are currently only possible with preprocessing, but they require only one new grammar rule and it is just a function call on the implementation side. The list nonemptiness key modifier (17) does very poorly: it solves only one problem, but still adds a rule to the grammar and a special case to the implementation. Virtual keys (14) are only marginally better than that. A single change to the parser can recognize all virtual keys, but each virtual key (for example |
Beta Was this translation helpful? Give feedback.
-
Starting from #153 (reply in thread), a few comments went a little bit sideways and were rather about the current discussion (#163). Quoted here for reasier reference:
I have to say I lean more towards the position of @spullara in this case. I understand that having to register a filter may be considered a barrier by some users, but look at it from the other side: Mustache has been around for 14 years. All that time, there has been no standard solution for first/last, with many implementations having no solution whatsoever other than data preprocessing (mine included). Despite that, it is the most widely ported templating language and it has a large and faithful crowd of users. I think that proves that Mustache's notational minimalism is appreciated and that many users are willing to give up some bells and whistles in exchange for that. I know I do. On top of that:
|
Beta Was this translation helpful? Give feedback.
-
Since the start of the spec's existence, this topic has come up in nearly every discussion. It touches on the soul of the Mustache language, or at least what various people think that soul should be. If we could form a consensus around some kind of explicit principle, I think that would help to guide future decisions.
We have a spectrum between two extremes, which I dub "purist" and "pragmatist". A purist prefers a minimalist grammar and preprocessing the data before feeding them to the template. A pragmatist prefers an expressive grammar and not needing to preprocess the data.
The killer argument for the purist side is that Mustache distinguishes itself from other template languages by having a minimalist and logic-free grammar. If users want bells and whistles, they have many other options to choose from. Mustache should not become like Handlebars, ERB or Jinja; that would defeat the point of the language.
The killer argument for the pragmatist side is that template authors are not always in control of the input data. @agentgt formulated it well in #147 (comment):
A radical purist might believe that lambdas should never have made it into the language. A radical pragmatist might believe that Mustache needs syntax for literal values, string operations and arithmetic expressions.
I would like to formulate the central question of this discussion as follows: where on this spectrum should Mustache try to be?
In our answers, let us appreciate that both killer arguments are true at the same time: minimalism is one of the main features that make Mustache unique and template authors are not always in control of the input data. We will be making a tradeoff, regardless of where we position ourselves on the spectrum.
Beta Was this translation helpful? Give feedback.
All reactions