opinions on inline server-side code?

Discussion in 'HTML' started by John Salerno, Feb 23, 2006.

  1. John Salerno

    John Salerno Guest

    After doing a little reading (I'm trying to figure out how to in-line
    Python code in my HTML), it seems like a lot of purists think that
    inline code is a bad thing (sort of like inline style). I was wondering
    what you guys think of that, since you are obviously very strict about
    things like style, HTML vs XHTML, etc. (although, I've never heard any
    criticism in this group of inline PHP, for example, such as when I asked
    about it a while back).

    Thanks.
     
    John Salerno, Feb 23, 2006
    #1
    1. Advertising

  2. John Salerno

    Toby Inkster Guest

    John Salerno wrote:

    > After doing a little reading (I'm trying to figure out how to in-line
    > Python code in my HTML), it seems like a lot of purists think that
    > inline code is a bad thing (sort of like inline style). I was wondering
    > what you guys think of that, since you are obviously very strict about
    > things like style, HTML vs XHTML, etc. (although, I've never heard any
    > criticism in this group of inline PHP, for example, such as when I asked
    > about it a while back).


    PHP (and ASP and others too) is clearly designed to be scattered in little
    droplets throughout an HTML file:

    <? require_once "myfunctions.php"; ?>
    <h1><? print get_title_from_db(); ?></h1>
    <div id="content">
    <? print get_content_from_db(); ?>
    </div>
    <!-- and so on -->

    And when you just need to add little splashes of dynamicism here and
    there, that works fairly well.

    However, for larger projects, you'll probably find it easier to do things
    the opposite way around:

    <?
    require_once "myfunctions.php";
    $t = get_title_from_db();
    $c = get_content_from_db();
    printf("<h1>%s</h1>\n", htmlspecialchars($t));
    printf("<div id=\"content\">%s</div>\n",
    htmlspecialchars($c));
    print "<!-- and so on -->\n";
    ?>

    only "dropping out of PHP mode" occasionally, when you have large chunks
    of HTML to output (that hasn't come from a database, or been dynamically
    generated in any other way).

    For my current blog project, I've got about 6000 lines of code so far, and
    all of them are PHP, as per the second example. (No plain HTML yet, and
    none planned!)

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Feb 23, 2006
    #2
    1. Advertising

  3. John Salerno

    John Salerno Guest

    Toby Inkster wrote:

    > For my current blog project, I've got about 6000 lines of code so far, and
    > all of them are PHP, as per the second example. (No plain HTML yet, and
    > none planned!)


    You frighten me! ;)
     
    John Salerno, Feb 23, 2006
    #3
  4. John Salerno

    cwdjrxyz Guest

    John Salerno wrote:
    > After doing a little reading (I'm trying to figure out how to in-line
    > Python code in my HTML), it seems like a lot of purists think that
    > inline code is a bad thing (sort of like inline style). I was wondering
    > what you guys think of that, since you are obviously very strict about
    > things like style, HTML vs XHTML, etc. (although, I've never heard any
    > criticism in this group of inline PHP, for example, such as when I asked
    > about it a while back).


    First, inline style is not a bad thing per se, and is completely valid
    according to W3C standards up to and including xhtml 1.1. One can use
    an external style sheet, a style sheet in the head of the page, or a
    style many places in the body as most convenient. If you use most of
    the same style elements on many pages, then an external style sheet is
    the way to go. If you are using most style elements only on a single
    page, then a style sheet in the head is the way to go. Or the head
    stylesheet can be used to override a few elements in an external style
    sheet that are different for the page. This is cascading. Likewise, the
    same considerations apply to a style in the body of the page at perhaps
    a division or paragraph level. If, for example, you are going to use a
    style only in a single paragraph or division for a single page, I find
    it pointless to write the style for it in a head style sheet and then
    also have to reference this at the paragraph or division where it
    applies. If you for example use javascript to detect something such as
    screen width after the page is downloaded, and then use this detected
    width to write a style based on it using javascript, then working at
    the division or paragraph method often is by far the most simple method
    to go.

    About the same consideration apply for deciding if you want to use an
    external script, a big script on the page, or several small scripts
    scattered throughout the page. You do what is most convenient.

    Again about the same applies for a serverside script such as php. I
    have some pages that are mostly php, some with just a bit of php, and
    some with many small bits of php. In some cases you will use both php
    and javascript, because some things, such as changing a color after the
    page has downloaded, need javascript to do it.

    In most cases the "grammar" of how you handle your css, javascript, or
    php will make little difference in how fast the page loads. If you are
    concerned about download time, reducing image and other media bit size
    often is far more effective than fussing with code. Practical
    considerations are to use a formalism that you can easily modify after
    not seeing the page for a long time, and try to use external code or
    head code when you can for things that get repeated often so that you
    do not have to reinvent the wheel every time you write a new page much
    like an old page.
     
    cwdjrxyz, Feb 23, 2006
    #4
  5. In article <>,
    cwdjrxyz <> wrote:
    >First, inline style is not a bad thing per se, and is completely valid
    >according to W3C standards up to and including xhtml 1.1. One can use
    >an external style sheet,


    Because nothing beats subjecting dialup users (there's still LOTS) to
    a page, semi readable only to have it jump around a second later
    to something completely different.

    I consider it a good thing if you can read a page that's only
    partially loaded. If you can give somebody something in one MTU
    that'll take them a few seconds to read what they experience is
    for all intents and purposes as goood as instant page loading.

    --
    Need Mercedes parts ? - http://parts.mbz.org
    Richard Sexton | Mercedes stuff: http://mbz.org
    1970 280SE, 72 280SE | Home page: http://rs79.vrx.net
    633CSi 250SE/C 300SD | http://aquaria.net http://killi.net
     
    Richard Sexton, Feb 23, 2006
    #5
  6. John Salerno

    Andy Dingley Guest

    On Thu, 23 Feb 2006 17:42:46 GMT, John Salerno
    <> wrote:

    >it seems like a lot of purists think that
    >inline code is a bad thing (sort of like inline style).


    No, nothing like it. Inline styles are fine in their place and (in some
    cases, such as lots of absolute positioning) certainly better than huge
    dynamically generated CSS documents.

    Compare ASP (lots of in-line code) and good Java server-side code (no
    in-line code, and the tools to make this possible) though. If someone
    learns ASP first, they're ruined for Java. Conversely the only way to
    get good ASP coders is to teach them JSP and Servlets first.
     
    Andy Dingley, Feb 24, 2006
    #6
  7. John Salerno

    Toby Inkster Guest

    John Salerno wrote:
    > Toby Inkster wrote:
    >
    >> For my current blog project, I've got about 6000 lines of code so far, and
    >> all of them are PHP, as per the second example. (No plain HTML yet, and
    >> none planned!)

    >
    > You frighten me! ;)


    It's only a tiny fraction complete so far. Will probably be about 20K-30K
    lines of code when finished. (My line counts include comments, but not
    blank lines.)

    One of my reasons for using as little HTML as possible in this project is
    that it's designed to validate as HTML 4.01, XHTML 1.0 and XHTML 1.1, with
    some support for ISO HTML and the current XHTML 2.0 draft. Now *that's*
    frightening! (FWIW, it will also play nicely with both PostgreSQL and
    MySQL.)

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Feb 24, 2006
    #7
  8. John Salerno

    John Salerno Guest

    Toby Inkster wrote:

    > One of my reasons for using as little HTML as possible in this project is
    > that it's designed to validate as HTML 4.01, XHTML 1.0 and XHTML 1.1, with
    > some support for ISO HTML and the current XHTML 2.0 draft. Now *that's*
    > frightening! (FWIW, it will also play nicely with both PostgreSQL and
    > MySQL.)
    >


    It's comments like this that make me realize how little I know about any
    of these subjects! :)

    Any chance I could see a snippet of this code, just for kicks? I'm still
    not sure how HTML is created dynamically through scripts.
     
    John Salerno, Feb 24, 2006
    #8
  9. John Salerno

    Toby Inkster Guest

    John Salerno wrote:

    > Any chance I could see a snippet of this code, just for kicks? I'm still
    > not sure how HTML is created dynamically through scripts.


    I posted these two to alt.www.webmaster a little while ago:

    Templating Engine:
    http://test.tobyinkster.co.uk/Preview/templating_engine.phps

    Syntax Highlighting:
    http://test.tobyinkster.co.uk/Preview/Syntax-Highlighting/test.phps
    Result:
    http://test.tobyinkster.co.uk/Preview/Syntax-Highlighting/test.php

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Feb 24, 2006
    #9
  10. John Salerno

    John Salerno Guest

    Toby Inkster wrote:
    > John Salerno wrote:
    >
    >> Any chance I could see a snippet of this code, just for kicks? I'm still
    >> not sure how HTML is created dynamically through scripts.

    >
    > I posted these two to alt.www.webmaster a little while ago:
    >
    > Templating Engine:
    > http://test.tobyinkster.co.uk/Preview/templating_engine.phps
    >
    > Syntax Highlighting:
    > http://test.tobyinkster.co.uk/Preview/Syntax-Highlighting/test.phps
    > Result:
    > http://test.tobyinkster.co.uk/Preview/Syntax-Highlighting/test.php
    >


    Yeesh! Like I said, you frighten me! Then again, I guess this *should*
    look like a foreign language to me, since I haven't messed with PHP much
    yet anyway. :)
     
    John Salerno, Feb 24, 2006
    #10
  11. John Salerno

    Jim Higson Guest

    John Salerno wrote:

    > After doing a little reading (I'm trying to figure out how to in-line
    > Python code in my HTML), it seems like a lot of purists think that
    > inline code is a bad thing (sort of like inline style). I was wondering
    > what you guys think of that, since you are obviously very strict about
    > things like style, HTML vs XHTML, etc. (although, I've never heard any
    > criticism in this group of inline PHP, for example, such as when I asked
    > about it a while back).


    Personally, I find the "PHP in HTML" and "HTML in PHP" models pretty messy
    except for adding little bits of dynamic content to the pages.

    PHP in HTML: all the <?php and ?> tags ruin the flow of the HTML and make it
    difficult to read. Difficult to use for large projects, where much of the
    code doesn't belong in any particular place in the HTML.

    HTML printed from PHP: Discourages Indentation on the HTML so it is hard to
    see at a glance which echo "<div>"; corresponds to which echo "</div>".

    My preferred way is to use PHP for the SQL plus a templating engine for the
    HTML (ironic since PHP was originally just a templating engine). My
    preferred engine is Smarty:

    http://smarty.php.net/

    --
    Jim
     
    Jim Higson, Feb 26, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page