Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: The hidden charm of Template::Toolkit (and templates generally)

by exussum0 (Vicar)
on Jan 07, 2008 at 03:02 UTC ( #660739=note: print w/ replies, xml ) Need Help??


in reply to The hidden charm of Template::Toolkit (and templates generally)

The best reason to use any template language, in any system, is in the readability and functionality a template language brings.

Yes, your function is somewhat readable. Very much so. The problem is, it doesn't scale. For any HTML entity, any visual reference, it can affect another entity or reference. If I want to apply css, js and what not, I don't have a single document that contains everything in a single view. What's worse is, to find any particular piece, I have to go backwards and figure out what calls what. In a template, things are intended to be more flat - like a program w/ no user defined functions. Everything reads top down, loops get hit, variables get assigned an life goes on.

The intended target is also valuable. I can hand a template to a designer and state, "This is the syntax, be it simple like Html Tmplate, or Mason, tweak it so it's a horizontal scrolling page instead of vertical." Less things to break. The separation is nice because it is a controlled separation. Sure you can get around it, but it's fairly obvious when it gets complex. The reverse is true too. I can take an HTML file, and replace a mockup of a few rows into a loop quite easily, pass it back and ensure life is good.


Comment on Re: The hidden charm of Template::Toolkit (and templates generally)
Re^2: The hidden charm of Template::Toolkit (and templates generally)
by shmem (Canon) on Jan 07, 2008 at 10:41 UTC
    The best reason to use any template language, in any system, is in the readability and functionality a template language brings.

    Readability: only if you have a high ratio of static/dynamic code; functionality: only if restricting is a benefit.

    The problem is, it doesn't scale. For any HTML entity, any visual reference, it can affect another entity or reference. If I want to apply css, js and what not, I don't have a single document that contains everything in a single view. What's worse is, to find any particular piece, I have to go backwards and figure out what calls what.

    What do you mean by 'scaling'? A template doesn't save you from "entities affecting each other". You have a single document only in the case of trivial pages with sparse dynamic content. If you have e.g. inclusions (of other templates), reading gets equally difficult, an you have to go back to look where each bit comes from.

    And if you have a different language, e.g. that of Template::Toolkit, you have to go back to the calling code to see what every token means.

    [% INCLUDE debugtxt msg="file: $error.info" %]
    Quick, was is info here? A hash key, a method, function, something else?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      What do you mean by 'scaling'? A template doesn't save you from "entities affecting each other". You have a single document only in the case of trivial pages with sparse dynamic content. If you have e.g. inclusions (of other templates), reading gets equally difficult, an you have to go back to look where each bit comes from.
      By scaling I mean, you start out w/ HTML (or text) and you add logic to it. Some pages will be horridly complex and things start to get messy, sure, as we go off to infinity. Point is, you start off w/ a document and start to add the logic. If there's very little, the template looks pretty much like what you started w/. Doing it as code, it starts out as something highly unreadable, and it takes diligence to make it not look like a mess.

      And yes, I can include to death, but I shouldn't be using goto, i mean spaghetti code, I mean includes except as a matter of large scale convenience.

      In the end, I could throw it all away and say it really doesn't matter. It's all turing complete and equivalent. You can create the same mess in any fashion. It's the starting point and the usability of the tech that a) promotes a certain type of usage and b) gives you a good starting point. For template languages it's, start off w/ large documents and then make them dynamic. It's not, take something dynamic and make it output HTML.

      Same holds true for other things. SQL is equivalent by using hashsets and mutex locks to mimic the behaviour, but hell, I'll make people cry doing that. I can probably do business logic in PL/SQL or TransactSQL, but that's not very nice either.

      As for tokens meaning something, I hope you are using variables in templates that mean something. I hope there's documentation, be it wireframe or graphical mockups. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://660739]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-09-18 01:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (104 votes), past polls