On 2004.08.13, Robert Seeger <[EMAIL PROTECTED]> wrote:
> # Lets output some financial data
> # We need to escape the $ for the monetary units
>
> ns_puts [subst {
>      <tr>
>          <td><a ref="link[set $i]">Item $i</a></td>
>          <td>\$$amount($i)</td>
>      </tr>
> }

Compare that to:

  %>
     <tr>
         <td><a ref="link<%= [set $i] %>">Item <%= $i %></a></td>
         <td>$<%= $amount($i) %></td>
     </tr>
  <%

There's a LOT more "escaping" going on in the ASP-style version -- <%=
and %> are used instead of just one \ ...

> For that type of output, yes its not the best choice. However, there are
> situations where doing it inside an ns_adp_puts is the more hideous of
> the choices. For example:
>
> <table>
> <%
> foreach row $rows {
>     foreach {
>         item1 item2 item3 item4 item5 item6 item7
>     } $row {break}
>     ### Output a lot of html for each row of data
>     %>
>
>     <tr>
>        <!-- 30 lines of html here that output the items
>          -- and the form elements involved with them
>          -->
>     </tr>
>
>     %>
>     ### Done with row
> }
> %>
> </table>

I fail to see why the following is more "hideous" than your version
above:

    <table>
    <%
    foreach row $rows {
        foreach {
            item1 item2 item3 item4 item5 item6 item7
        } $row {break}
        ### Output a lot of html for each row of data
        ns_adp_puts [subst {
        <tr>
           <!-- 30 lines of html here that output the items
             -- and the form elements involved with them
             -->
        </tr>
        }]
        ### Done with row
    }
    %>
    </table>

Instead of %> and <%, my version uses "ns_adp_puts [subst {" and "}]".

The difference is, the actual "30 lines of HTML" that would be where the
HTML comment is in your version will have much more escaping using <%=
and %> than in mine where I only need to escape $ and [ and only IF they
actually appear in the HTML.  In your version, every single time you
want to interpolate some Tcl chunk, you'll need to "escape" it with <%=
and %>.

Regardless, there's too many folks out there who cut their teeth on web
scripting on VBScript and ASP to not at least support this style, but
the less ASP-style ADP code that's out there, the better.  Just because
it's a popular doesn't mean it's better, and most people just think it's
better because that's what they learned first.  It's just resistance to
change ...

Unless, people really want to debate that Microsoft's known for
inventing things that really ARE best practices ... as opposed to just
creating a lot of inertia.  I mean, all of those "enhancements" to the
HTTP protocol and JavaScript and CSS that are in MSIE that aren't
supported by other browsers ... everyone should do it that way, the
pages just LOOK better with those extra features ...

-- Dossy

--
Dossy Shiobara                       mail: [EMAIL PROTECTED]
Panoptic Computer Network             web: http://www.panoptic.com/
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of 
your email blank.

Reply via email to