Hacker News new | past | comments | ask | show | jobs | submit login

>Who uses a text editor that inserts whitespace into HTML?

I do as does anyone else who uses Zen Coding (or emmet).

>Why use an editor that adds whitespace in the first place?

Because it makes the code way, way more readable. Indentation allows you to easily see the structure of the HTML, so that you can see what is a descendant of what.

Look at this and tell me whether "Man Made" is part of "Debris" or if it's a separate sublist:

    <ul>
    <li>Debris:
    <ul>
    <li>Sand</li>
    <li>Dirt</li>
    <li>Man Made:
    <ol>
    <li>Broken glass</li>
    <li>Pennies</li>
    </ol>
    </li>
    </ul>
    </li>
    <li>Animals:
    <ul>
    <li>Cats</li>
    <li>Dogs</li>
    <li>Chimps</li>
    </ul>
    </li>
    </ul>
Now look at it with indentation:

    <ul>
        <li>Debris:
            <ul>
                <li>Sand</li>
                <li>Dirt</li>
                <li>Man Made:
                    <ol>
                        <li>Broken glass</li>
                        <li>Pennies</li>
                    </ol>
                </li>
            </ul>
        </li>
        <li>Animals:
            <ul>
                <li>Cats</li>
                <li>Dogs</li>
                <li>Chimps</li>
            </ul>
        </li>
    </ul>



Obviously (to me anyway) you're right, and I'm surprised there are people who don't indent their HTML like that. But a thought just occurred to me -- why don't editors do this automatically and without creating actual whitespace (tabs/spaces)? If you look at XML in your web browser it will automatically be formatted with indents based on tag hierarchy .


I see your point, but I think there are a few solid reasons it would be a bad idea.

The basic text file (at least in unix) is king, and the medium by which we transport all sorts of code around. Adding a layer of asbtraction to an editor like that, where it shows you one thing but saves the file differently, breaks this premise and means your new editor now doesn't play well with others.

- Unless you source control is in on it, you are going to suddenly see a different file than you were working with before when resolving conflicts.

- Your whole team is now forced to use your editor to get the same view of the code as you are.

- grepping, line counts, most third party text mapulation/wrangling services become moot unless savvy to the context of your editor


After I wrote that, I realized that all editors would need to have the same capability which is pretty much a non-starter (and whitespace is universal). Your other points are well taken too.


What is the benefit to showing indentation but not actually including it? It is less intuitive and offers little to no benefit -- that would appear to be the why.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: