http://qs321.pair.com?node_id=133169


in reply to Re: Code Critique
in thread Code Critique

For me personaly, I've looked at them and while HTML::Template is kind if cool it seems that much of the time it just wouldn't be powerful enough for some of what I want to do. And why use templates when you have to output/construct half the HTML yourself ;-)? >Forgive my english, I'm Australian.
I suppose I can let it slide this time ;-)

--
perl -p -e "s/(?:\w);([st])/'\$1/mg"

Replies are listed 'Best First'.
(jeffa) 3Re: Code Critique
by jeffa (Bishop) on Dec 20, 2001 at 22:36 UTC
    You still miss the bigger picture, it's not about making the generation of HTML from Perl code easier or abstract - it's about moving the HTML out of the Perl code. Trust me, this is a good thing. Also, understand that I didn't get it at first either - the whole 'seperation of presentation from logic' seemed like a complete waste of time. Remember, my first job out of school was developing in Cold Fusion. I literally had to take over the job of the UI designer, because they were too afraid to touch the site once all of their HTML had been moved into the Cold Fusion code. (you have read my tut on HTML::Template, right? ;))

    I have heard you mention in the CB, why use a templating system when CSS is available. Because CSS isn't powerful enough, it only defines markup. Templating systems allow you to package up all dynamic content for a page in a convenient (well, convenient for a Perl programmer) data structure and apply it to HTML. Very similar to CSS, but instead it offers the power to control large chunks of presentation - only display this for users logged in, only display that for anonymous users. How do you think this site does what it does? ;)

    You mentioned HTML::Template wouldn't be powerful enough for you most of the time. I can't agree with that, but i can agree that a templating system might be 'over-kill' most of the time. If you are working with a team of developers and a team of UI designers, then you will see the power of templating systems.

    I am not saying that you should rush out and port all of your existing sites to a templating system, i am just saying please don't knock it till you have fully experienced it.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)
    
Re: Re: Re: Code Critique
by vladb (Vicar) on Dec 19, 2001 at 21:37 UTC

    I agree... discounting a few things that HTML::Template may be useful for, I always found it hard to actually 'wrap' my code around a template. I know that if separating code from content is an issue, then wouldn't it be simpler to move on to Mason? However, I'm not particular fan of this either since many Mason scripts I looked at appeared to be quite a mess.

    Having said that, I am actually trying to move more towards splitting display logic from program logic. One way to do this, I think, would be to have your program generate and store all of its 'working' data mean to be displayed in some fashion in a hash or some complex enough structure which yet could be looped through/accessed via a templating script (such as <TMPL_LOOP ... > </TMPL_LOOP> implemented in HTML::Template).

    Since I'm yet not a strong believer in Perl templating utilities, would anyone with some related experience share in his/her joys of using them? I'd be interested in hearing from someone who was in a position similar to I'm in now (that is 'hardly decided') and how they managed to integrate this concept in their code.

    PS: my native language is Russian so don't mind my English! ;-)

    "There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith
      For small, personal projects or projects for which you are the 'display designer', the notion of using a template system seems like overkill. However if you ever get to the point of working on a larger project and having a dedicated 'display designer', you'll end up singing the praises of a template system.

      What if your development team consisted of 2 coders and 1 UI person? You might be decent at UI, the other coder isn't, and your UI guy really isn't that good at perl. Each of you needs to be able to exercise your strengths and not be hindered by your weaknesses.

      • What happens when the UI person needs to make a decent sized structural change to the HTML? There's a pretty big risk that he's going to break the program.
      • How many times is the UI guy going to be editing the same script (for UI changes) at the same time that you need to edit it for code changes?
      • Have you ever had to alter the flow of your logic to accomidate what the layout of the HTML has to be?
      • Can you imagine the horror if this UI guy wants to try and use something like DreamWeaver to edit the HTML? *shudder*
      • What if you're building an turn key type of website and the buyers all want a different UI?
      Ask yourself each of these questions with "If I have a templated system the answer is:" and "If I do not then it's:".

      Here's a real world scenerio. A site that I, another coder, and a UI guy developed uses HTML::Template and just underwent a complete UI change, along with adding features. The total number of pages is nearly 300. How many of the existing perl modules do you think had to be changed to accomidate any UI changes the designer made? In our case, none of them.

      /\/\averick
      perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

        Agreed on every point! ;-).

        Maverick, since you've had earlier experience integrating a templating mechanism into your perl code (the backend for the site you've worked on), I'd like to repean an earlier question that I had. Did you have any difficulty integrating the templates? How did you overcome them? I'm really interested in knowing how you structured your display data so that it could be included within a template in any way the UI guy wanted to? Say, I had seen some complex templates with quite a bit of templating code.. how much of that did you have in your site?

        "There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith
        Firstly I'm a graphic designer by trade and only over the last six months have a started programming in perl, so this has always been a major gripe of mine.

        I agree with all but one of mavericks points. I use dreamweaver every day and I love it. Yes I can live without out it but when you are working to a deadline it produces clean code quickly.

        The use of a html templating system shouldn't be restricted to large sites.

        example:
        YESTERDAY: I wrote a site the other day that has a set of 30 thumbnails with large versions plus 8 normal pages. Rather than make 30 pages I wrote a script to look for the image name plus '_lrg.jpg'. Then a regex later and it dumps the image into my existing dreamweaver template and pipes that to display.
        TODAY: After a phone call I added a page to the site and only had to add one link in the template.
      I know that if separating code from content is an issue, then wouldn't it be simpler to move on to Mason? However, I'm not particular fan of this either since many Mason scripts I looked at appeared to be quite a mess.

      With embeded Perl it is very easy to write HTML/Perl pages which look like a mess. It requires some self-dicpline to control use of Perl in templates. But it is possible to do it in right way (put business logic in modules, use Perl code in templates only to produce output, separate big sections of Perl and HTML). There exist quite good examples of HTML::Mason code: sources of www.masonhq.com, sources of Request Tracker.

      --
      Ilya Martynov (http://martynov.org/)

        My try was http://plp.juerd.nl/, as I didn't really like the existing alternatives. There'll be a new version soon.
        The thought behind it is quite simple: s/// the page into a CGI script and eval it ;) Works like a charm.

        2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$