3 ms·
What are the compelling use cases for template languages that don’t support the full host language? Or: what do I gain from intentionally limiting myself to a
by WalterGR 5y ago
What are the compelling use cases for template languages that don’t support the full host language?
Or: what do I gain from intentionally limiting myself to a bespoke language that lacks many of the constructs of the language I’m writing the rest of my project in?
If I can’t be trusted to responsibly and successfully use that full language in templates, how can I be trusted to use it in all the rest of the code base?
- gsliepen 5y agoThere are many uses for templates, not all of them need you to use advanced language constructs in the template language. Personally, I'd rather have templates be relatively dumb, and use something like {{mustache}} (https://mustache.github.io/ https://mustache.github.io/).
- WalterGR 5y agoTrue, but then why not limit oneself to exactly that subset of the language that one considers non-advanced and relatively dumb, rather than let someone else make that call?
- tirpen 5y agoWho said it's about trusting you? It's very common for templates to be written by people who are not full developers. The HTML might be written by a designer, email-templates may be written by marketing etc. By limiting the power of the template language to only data display and simple conditionals and loops, you can those people to write templates far easier and you can let them upload new versions whenever they want with much less worries and you don't have to go through your full code review process just to update an email template.
- WalterGR 5y agoWell, you can’t trust anyone! :) Template languages are still languages, and it’s easy for even seasoned developers to make errors that have to be corrected between ‘upload’ and whatever deployment looks like in this scenario. Forget to double-up the closing curly-brackets? Blammo. I wonder how common it is in practice. Are there existing frameworks or (non-no/low code) CMSes that support that workflow? I.e. letting non-admins modify templates, ‘compiling’ them if necessary, running them over some sample input, and allowing iteration - before potentially breaking things in production? Limiting the language to avoid having to do a full security audit - that’s a good point.
- gpderetta 5y agoIn this specific case supporting the full host language would mean implementing a whole C++ compiler which might be a bit overkill.
- WalterGR 5y agoI would imagine a preprocessor (not the C++ one) would be used before re-implementing C++. :) Not having to use one could be a use case, though IMO I don’t know if that’s compelling enough…