Between the code I write and the code people send me to look at, I see a lot of code.
Some of it's good, some of it's bad, but most of it is just plain ugly!
While you may not deal with as much code as I do, most developers at
some point in their careers get thrown into the ring with someone else's
ugly old code.
I used to use the venerable HTML Tidy
to get the HTML portions of really ugly ASP code to a point where I could at
least figure out what was going on. These days I find myself using Tidy less and
less, and it's not because the stuff I get sent has gotten any prettier.
The tool I've been reaching for recently is the "Format Selection"
command in
Visual Web Developer
and Visual Studio 2005. It handles both HTML and code areas and is built right into the
development environment.
In order to use it you simply highlight the section of code that you want to reformat,
right click, and choose "Format Selection". Almost instantly the ugly code
is gone and in its place is shiny new code ready for editing (or in my case publication).
And best of all, it almost never messes up the output from the page... when viewed
in a browser the page should look just as it did before.
Oh and if for some reason you don't like the style of the resulting code, you can
even customize the formatting rules that are used to clean the code. If you
select "Formatting and Validation..." from the pop-up menu, you will be taken to
a dialog box that will let you tweak the output to your heart's content.
If you have a tip you would like to submit, please send it to:
webmaster@asp101.com.