How do you format your code?
I've put a lot of time into researching and formatting html. I see very few who use the style that I've adapted over the years.
Currently, I format my html so there are no breaks in tags. I remove all indents and spaces between tags. What I end up with is code where each tag occupies one line in my html in most instances. If there are soft returns or what is referred to as the <br> tag, then my line of code breaks there and starts on the next line.
Some say they prefer indented html as it is easier to navigate. I'm going to assume that it is all a matter of how you learned and what works best for you.
I will share some valuable observations. Since reformatting all of my clients code and building new sites using my method of formatting, I've seen an overall increase in the ability to secure and obtain pageoneresults.
How do you format your code? Why do you format that way? The reason I posted in this forum is because I'm an FP junkie. Hiss and boo all you want, but I know all the little secrets of the program! ;)
P.S. Validation is a must for me as it has now become second nature when developing sites. Yes, FP is capable of producing valid html in the right hands.
I write code using an indented style - especially when the if-then-elses get nested ten deep. Indentation makes the code structure visually clearer, and aids in finding problems. If I'm hand-coding HTML, I may or may not indent the code; I mostly use indentation for scripting and programming languages, but may revert to it for "tricky" tables or complex layouts in HTML.
Publishing to the web, however, is an altogether different matter; Once the code is debugged and tested thoroughly, then every single unnecessary character is mercilessly eliminated (I use an automated tool to do this). This regulary results in files 10% to 25% smaller than before, and that means faster page loads, fewer bills for bandwidth overages, and less stress on the server.
I use a "limited indent" style. Blocks are separated by carriage returns, but are only indented to represent nesting of block-level elements. Inline tags always fall inline.
This I believe to be a good compromise, allowing for readability without adding excessive weight ("white matter?") to documents (for HTML e-mail, we strip out all carriage returns, tabs, and non-content spaces after the final draft is approved).
|Since reformatting all of my clients code and building new sites using my method of formatting, I've seen an overall increase in the ability to secure and obtain pageoneresults. |
That would really be surprising. I do understand why SEs might favour valid HTML over invalid HTML. But I cannot think of any reason why they would prefer one code formatting style over another since the HTML spec clearly states that whitespace does not matter.
Could you explain in more details how you measured that increase?
Content positioning through the use of css. I've stripped all the tables and have absolutely positioned my divs in a particular order.
I am with pageonresults, perhaps a little looser, but I like to keep it compact without loosing too much readability. A big monitor helps for those long lines. I read somewhere that browsers will take up to a 255 character line in one gulp, longer lines speed rendering. Not sure if that is true, but makes more sense then waltzing through the table tags (I hate it when I see a line with just one tr tag).
Ok, that I can understand :). I thought code formatting was only about breaking up your code into different lines and indenting those lines, i.e. about the use of whitespace.
|brotherhood of LAN|
=> Click on "template" :)
-includes DOCTYPE,<title>,<meta description>,<generic style sheet reference> all on seperate lines
2 hard returns after <head>
<divs> seperated by 2 hard returns
<p>'s and </p>'s in same line and sandwiched immediated after <div>
I hardly ever use tabs and just use line breaks to seperate the "chunks", mainly <head> and <body> and seperate <divs>
I've found PHP great to alter "foreign" information to a more friendly code layout. It's handy for simple things like stripping out another webmasters code formatting "preference" and re-arrange it to your liking.
If all info came pre-formatted and in the correct format, how much easier would it be! :)
I tend to keep it all in one block as well, except for header info and one line break in between tables or div's.