Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'd like to add my humble 2 cents here:

I've came from a HTML background so this node really drew my attention.

I think that although is possible to do a clean separation of presentation and logic, sometimes it's not the best way to do it, because you end up messing with the readability of the page. Let me clarify this with a (silly) example:

Let's say that a user of your web system should see a red background if he/she has a "0" level or a blue background if he/she has a "1" level.

So, you could do this in two different ways (i'm coding this in a freely, lazy way so dont evaluate my code, this is just an example):

First way (separating logic and presentation):
if ($u_level == 0) { $bgcolor = "#FF0000"; } else if ($u_level == 1) { $bgcolor = "#0000FF"; } # tons of code... print<<<HTML <HTML> <HEAD> <TITLE> DaWolf's silly example </TITLE> </HEAD> <BODY BGCOLOR="$bgcolor"> <!-- tons of content... --> </BODY> </HTML> HTML;
Second way (mixing logic and presentation):
# tons of code... print<<<HTML1 <HTML> <HEAD> <TITLE> DaWolf's silly example </TITLE> </HEAD> HTML1; if ($u_level == 0) { print "<BODY BGCOLOR=\"#FF0000\">"; } else if ($u_level == 1) { print "<BODY BGCOLOR=\"#0000FF\">"; } print<<<HTML2 <!-- tons of content... --> </BODY> </HTML> HTML2;
The advantage of the second way in my point of view is that you don't need to go all the way up to understand what $bgcolor means and why it have this or that value, so the code is more easily understandable and more practical to debug.

That's why I think separation should be avoided unless you are not used to deal with HTML.

As I've stated before, this is just my humble opinion.

UPDATE:

Quick explanation: I've never used a Templating system with Perl, so I can't really give my opinion on that, but I've just tried to show the best way ***for me*** to code my pages =:c)

Best regards,

my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");

In reply to Re: Code and html separation - always or mostly doable? by DaWolf
in thread Code and html separation - always or mostly doable? by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-16 23:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found