Avoid Spaghetti Execution with the Judicious use of Inline Scripting

Rob Conery has kicked up a bit of a stink posting about the use of inline scripting in modern ASP.NET apps.

I may post more on this subject when I have time, but I had to just weigh in with my support for disciplined use of this technique, which can save you hundreds of pointless lines of code and execution cycles in a large app if used wisely.

One trick we use is to replace all those silly asp:LinkButton tags with a good ole anchor tag, and a call to a special utility class called LinkBuilder which knows how the site’s URLs hang together, like so:

<a href="<%= LinkBuilder.Show(catalogueItem) %>">Cancel</a>

This sort of markup can hardly be acused of being spaghetti code (the LinkBuilder method has a single line inside it), and means that we avoid what you might call ‘spaghetti execution’ when you actually come to spin the thing up.

Think about what a sequence diagram of the equivalent use of an asp:LinkButton with a wired OnClick event would look like. Eugh.

Published by Matt

I write software, and love learning how to do it even better.

Leave a comment

Your email address will not be published. Required fields are marked *