Did I not know that

Jump to menu

21 September 2003

Via kryogenix (via Ned Batchelder [via Raymond Chen]): Eric Lippert. I’ve jsut read it from top to bottom, where he started, and there’s plenty of fascinating stuff on VBScript and JScript, both of which he helped to design.

Like How does Active Server Pages use the script engines? Aside from explaining how ASP handles threading, it also mentions a barely-known Response.WriteBlock method. What this does is take a numbered ‘block,’ which is a string made up of the interleaved text in an ASP page, split by the bits of code within the delimiters. I didn’t explain that too well, so here’s an example.

Block 0<% Randomize %>Block 1<%= CStr(Rnd()) %>Block 2

Practical applications? Very few. It does provide an explanation for the speed increase in interleaving. Which in turn gives people like me a reason to ask others to write readable code, not ‘optimise’ by putting Response.Write everywhere, or worse, by bulding a huge string through concatenation and not a StringBuilder class.

But there is one other thing. Say you’re going to need to choose between lots of arbitary HTML snippets, can’t use the FSO, don’t want to double-quote everything, and will need to call on each one more than once. In this rather contrived example, you could put each bit in its own subroutine, or you could do something like this.

<% Response.Buffer = True %>
One<%%>Two<%%>Three<%%>Four
<% Response.Clear %>
<% Response.WriteBlock(0) %>, <% Response.WriteBlock(1) %>. <% Response.WriteBlock(0) %>&#160;<% Response.WriteBlock(1) %>&#160;<% Response.WriteBlock(2) %>&#160;<% Response.WriteBlock(3) %>

So, um, useless then. Barely-known or -mentioned for a reason.