Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Code Critique

by IOrdy (Friar)
on Dec 19, 2001 at 17:34 UTC ( #133113=note: print w/replies, xml ) Need Help??

in reply to Code Critique

Why dont people embrace the concept of templates? I'm the first to admit my perl knowledge is still very limited but one of the first modules I ever used was HTML::Template. Seperating your code/content/style just plain makes sense. (i.e what css is to html).

Apart from the use strict comment (I got use strict and -w bitch slapped into me when I first started sratching out code in perl) I think that templates should be the next thing you implement.

That's after any coding changes the monks suggest though.

Forgive my english, I'm Australian.

Replies are listed 'Best First'.
Re: Re: Code Critique
by belg4mit (Prior) on Dec 19, 2001 at 21:04 UTC
    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"

      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.


      (the triplet paradiddle)

      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.

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

        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, sources of Request Tracker.

        Ilya Martynov (

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2020-08-13 03:22 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (69 votes). Check out past polls.