ASP.NET: Rethinking Inline Scripting
I came across an article called Crazy Talk: Inline Scripting and Code-Behind and it really made me rethink the way I program. The article discusses how the “taboo” of inline scripting shouldn’t really be taboo anymore because, if done responsibly, it can be extremely effective in cutting down code. As a sort of experiment/form-reuse, I took a working form from one project to implement in a new project I’m working on and tried using inline scripting where it was required.
I was basically blown away by how much simpler it was to just use
<%= %> for implementing little things, such as name, address, etc. rather than having to deal with literals on the code behind. The codebehind was cut from 58 lines to two—four if you count the declaration of objects to use for binding the UI—and the same exact result is achieved. I don’t think my codebehind was messy either, just a lot of string concatenation and setting literal
Don’t take this as a license to completely rid yourself of codebehind pages and go nuts building everything into your .aspx page. Server side coding still has its purpose and is still more powerful than inline scripting, and many things are still easier to do on the server side. Just don’t think that it’s still “bad practice” to weave inline scripting into your source code. When used responsibly, it can make a lot of things a heckuva lot easier.
No comments yet.