Do you care about indentation?

A bad indentation is a torture.

I could hardly understand why so many people could post their code with badly broken indentation in the forum. :(

But at the same time, it has been very long since I gave up the useless effort to output the final HTML with “correct” indentation. :P

So I’d like to know what you think about indentation.

[color="#008000"]NOTE: moved to proper section (General PHP Topics instead of General Discussion for Yii 1.1.x)[/color]

I vote for the 3, PHP, JS, HTML and final output.

Why is it difficult for you? Of course, sometimes it doesn’t work as expected, but I’ve finally set my IDE to spaces and automatically convert any tab in my sources and switch it to 4 spaces.

I use Komodo Edit (the free version) for Mac OS X and it works fine. Of course, in some older projects, it was very far from my goals…

Um, maybe I was not clear enough. ::)

Yes, we can write views, partial views or widgets so that they will produce a piece of HTML output that has a clean indentation. Some tools have clever functions to help us do it.

But once you have implanted a partial view or a widget in a view, and put the content view into the layout view, it’s impossible to maintain a clean indentation in the HTML output as a whole.

I once had a chance to read a code trying to produce a well indented HTML output as a whole.

In it, the HTML fragment codes had lengthy leading spaces so that they could fit well into the main code. And some utility subroutines had a parameter named ‘indent_depth’ in order to change the leading spaces. And what you’ve got after all is a set of source codes that are very hard to read and maintain.

For code, yes, I’m very anal retentive. For what it looks like in view source of a browser … I gave up.

Voted for #2. It’ll just leave me with the feeling of having written clean and reproducable code. As for the finalö output: I gave up on that a long time ago. If I generate (X)HTML via XSL/T, I tend to strip unimportant whitespaces alltogether. Pages compress a bit better that way.

I voted 2.

Because I want to be able to compress the output to the browser.

Human readability is not really a concern to me, performance is.

However, when debugging, readable page source is a godsend.

So I want to toggle it.

There’s Firebug for that B)

Voted 2…imho, final output is important only to machines (like .exe code in compiled languages)

To developers, just give a good source code

Also, totally agree with JacMoe and Da:Sourcerer whitespaces in final output are bytes do download and Firebug does its job very fine


gzip FTW :)

The performance of deflate/gzip/bzip2 depends on the input ;)

Well I said gzip because I voted for max indentation, so that gives lots of useless spaces for the browser’s interpretation.

gzip (any?) compression algorithm should be effective because we’re talking about HTML (text) files.

My home page with very good HTML/CSS separation weighs 18,534 bytes for the HTML alone (230 lines). It’s gzipped to 5,256 bytes. With no indentation at all, the same HTML weighs 14,682 bytes. When gzipped, it’s 5,039 bytes.

See my point? 200 bytes are imho worth the indentation. And I’m not even using mod_deflate because I don’t have it on my shared host.

Now, according to my experience, sometimes proper HTML output indentation is necessary because a closing tag is possible to miss, and browser interpretations can vary, especially prior to HTML5 (which introduces optional closing tags by design). And Safari inspector (the one I use most for HTML) show only beautified/indented and even closed-tag HTML code, so it’s not the exact copy of the source. I think I remember FF has the same behavior… but maybe I’m wrong.

Output has really nothing to do with the source code - HTML and PHP.

Indentation matters for that.

What gets sent to the browser, however, is none of our concern.

I usually compress the heck out of my CSS too…

Yes, indeed. But in my experience, (X)HTML with all unnecessary whitespaces (that includes CRs, LFs and tabs) stripped tends to compress even better. It’s all about getting the last bit out of it B)

Imo with gzip on its not worth the stripping. 200 Bytes more just for white spaces even seems quite high to me. Even with a huge amount of visitors like wikipedia or youtube don’t bother with this.

Also if you consequently stip white spaces you will have to have 2 different view files one for editing and one (stripped) for publishing. Imho its not worth it for HTML.

I do care about indentation, but usually auto format works pretty well, so it’s not a big issue for me.

Hm, read again how I generate my output. Stripping them is basicaly a free operation by specifying

<xsl:output method="html" indent="no"/>

Yes, we sometimes have to examine the raw html output to debug. The raw html can have errors like missing opening/closing tags or overlapping tags. But those errors will be covered up by the browsers’ parser, and we will see only the corrected DOM tree.

So I admit that cleanly formatted raw html output has some advantage. But it is very small and not worth the effort. We can use our favorite editor to check the matching of tags, and it doesn’t matter how beautiful the html is indented when we do that kind of debugging.

for me indenting php and javascript codes is a must first. why it because these are the codes the produces the html code in your views(this is usually my case). And lastly indent the html code in your views… its really a torture to see a unindented code hahaha

anyways why indent the html output code? hahaha is there any good man can perfectly indent a html code after it is produced by server-side code to the client-side?

if there is… then TEACH ME!! ^___^

Well, you could pass it through tidy, which can repair broken HTML and take care about indentation at the same time. However, I found tidy’s output rarely statisfying <_<