indentation

Discussion in 'HTML' started by mbstevens, Aug 25, 2006.

  1. mbstevens

    mbstevens Guest

    For the following code snippets from
    a strict doctype page,
    which of the following styles of
    indentation do you prefer?

    And do you have a style that is unlike any of these
    that we should have a look at?

    ____________________________________________
    HTML Tidy output with '-i' indentation set:
    _____________________________________________

    <body>
    <p class="ahem">ljfdlsfjd ksldfjlsdjk lsjdlsdj ldkfjlf jdksllsdj
    lsjlsjd jlsdkfj fjkdlflkf jldksjflsjf ldsjflsdj jfdlsjlds</p>

    <ul class="ahem">
    <li><a href="http://www.mozilla.org/" class="dark">Download
    Mozilla or Firebird</a></li>

    <li><a href="http://www.opera.com/" class="dark">Download
    Opera</a></li>
    </ul>
    </body>

    _______________________________________________
    vaguely Lispish:
    _______________________________________________
    <body>
    <p class="ahem">ljfdlsfjd ksldfjlsdjk lsjdlsdj ldkfjlf jdksllsdj
    lsjlsjd jlsdkfj fjkdlflkf jldksjflsjf ldsjflsdj jfdlsjlds
    </p>
    <ul class="ahem">
    <li>
    < a href="http://www.mozilla.org/" class="dark">Download
    Mozilla or Firebird
    </a>
    </li>
    <li>
    < a href="http://www.opera.com/" class="dark">Download
    Opera
    </a>
    </li>
    </ul>
    </body>


    _______________________________________________
    contained levels:
    _______________________________________________
    <body>
    < p class="ahem">ljfdlsfjd ksldfjlsdjk lsjdlsdj ldkfjlf jdksllsdj
    lsjlsjd jlsdkfj fjkdlflkf jldksjflsjf ldsjflsdj jfdlsjlds
    </p>
    <ul class="ahem">
    <li>
    < a href="http://www.mozilla.org/" class="dark">Download
    Mozilla or Firebird
    </a>
    </li>
    <li>
    < a href="http://www.opera.com/" class="dark">Download
    Opera
    </a>
    </li>
    </ul>
    </body>


    _________________________________________________
    Flat, spaced:
    _________________________________________________
    <body>


    <p class="ahem">ljfdlsfjd ksldfjlsdjk lsjdlsdj ldkfjlf jdksllsdj
    lsjlsjd jlsdkfj fjkdlflkf jldksjflsjf ldsjflsdj jfdlsjlds
    </p>


    <ul class="ahem">

    <li><a href="http://www.mozilla.org/" class="dark">Download
    Mozilla or Firebird</a>
    </li>

    <li><a href="http://www.opera.com/" class="dark">Download
    Opera</a>
    </li>

    </ul>


    </body>
    </html>
    mbstevens, Aug 25, 2006
    #1
    1. Advertising

  2. mbstevens

    dfloss Guest

    Tab indents aren't worth the trouble, imho. We use two or three spaces.
    dfloss, Aug 25, 2006
    #2
    1. Advertising

  3. mbstevens <> writes:

    > which of the following styles of
    > indentation do you prefer?
    >
    > And do you have a style that is unlike any of these
    > that we should have a look at?


    > < a href="http://www.mozilla.org/"

    ^

    This is not wrong (the end tag further on is, though), but you do
    realise that's not a STAGO delimiter in this context, do you?


    Since whitespace between tags is often problematic (e.g. CSS bugs, DOM
    discrepancies), the best way of formatting HTML is to remove it (the
    whitespace, not the HTML :). I wouldn't indent myself, but of course
    you can if you wish, e.g.

    <body
    ><p

    class="ahem"
    >ljfdlsfjd ksldfjlsdjk lsjdlsdj ldkfjlf jdksllsdj lsjlsjd jlsdkfj

    fjkdlflkf jldksjflsjf ldsjflsdj jfdlsjlds</p
    ><ul

    class="ahem"
    ><li
    ><a

    href="http://www.mozilla.org/"
    class="dark"
    >Download Mozilla or Firebird</a
    ></li
    ><li
    ><a

    href="http://www.opera.com/"
    class="dark"
    >Download Opera</a
    ></li
    ></ul
    ></body
    ></html
    >


    I appreciate the copy in the paragraph, BTW. I've seen a lot of pages
    with an 'ahem' class, and they all had an idiotic message attached.


    --
    ||| hexadecimal EBB
    o-o decimal 3771
    --oOo--( )--oOo-- octal 7273
    205 goodbye binary 111010111011
    Eric B. Bednarz, Aug 26, 2006
    #3
  4. Eric B. Bednarz wrote:

    [snip]

    > Since whitespace between tags is often problematic


    Often?

    > (e.g. CSS bugs, DOM discrepancies),


    If a script depends upon an exact, node-for-node representation of the
    document tree, it's probably not very robust. There's certainly no need
    to use whitespace nodes as an excuse for munging markup: use a loop to
    traverse siblings in the document tree and test the node type (watch out
    for IE5.x and comment nodes).

    Even if markup is altered to remove whitespace between tags, there's no
    need to reformat the entire document.

    > the best way of formatting HTML is to remove [the whitespace]


    That's horrific, in my opinion.

    [snip]

    Mike
    Michael Winter, Aug 27, 2006
    #4
  5. Michael Winter <> writes:

    > Eric B. Bednarz wrote:


    >> Since whitespace between tags is often problematic

    >
    > Often?


    Often enough (in practice, not even generally taking mixed content
    models in account). I can say offhand that IE lte 6 has a problem with
    list elements seperated by whitespace if they contain child elements
    with the display property changed from inline to block, and I've seen
    whitespace related problems regarding tables the other month in a dutch
    newsgroup.

    > If a script depends upon an exact, node-for-node representation of the
    > document tree, it's probably not very robust. There's certainly no
    > need to use whitespace nodes as an excuse for munging markup: use a
    > loop to traverse siblings in the document tree and test the node type
    > (watch out for IE5.x and comment nodes).


    If I wanted to write a library, yes. :->
    If I know how the markup is generated, I don't see a real benefit in
    the overhead of using a loop as an extra safety-net when I could address
    a particular element directly. I would agree that this is quite
    case-dependent, though.


    [markup formatting a la <http://www.w3.org/2000/08/lb2/>]

    > That's horrific, in my opinion.


    Go shiver, it's not a new idea and even part of a standard

    <http://www1.y12.doe.gov/capabilities/sgml/wg8/document/n1920/html/clause-A.4.5.html#clause-A.4.5.2>

    and better don't ever use Jade then. :)


    FWIW, I even find it very readable. Of course YMMD.


    --
    ||| hexadecimal EBB
    o-o decimal 3771
    --oOo--( )--oOo-- octal 7273
    205 goodbye binary 111010111011
    Eric B. Bednarz, Aug 28, 2006
    #5
  6. Eric B. Bednarz wrote:

    > I can say offhand that IE lte 6 has a problem with list elements
    > seperated by whitespace if they contain child elements with the
    > display property changed from inline to block,


    That's the most intrusive example that I recall as well, yet it's easily
    fixed using only CSS. There's no need to alter the markup.

    > and I've seen whitespace related problems regarding tables the other
    > month in a dutch newsgroup.


    Nothing comes to mind here, but I don't style tables that often, anyway.

    [MLW:]
    >> If a script depends upon an exact, node-for-node representation of
    >> the document tree, it's probably not very robust. There's certainly
    >> no need to use whitespace nodes as an excuse for munging markup:
    >> use a loop to traverse siblings in the document tree and test the
    >> node type (watch out for IE5.x and comment nodes).

    >
    > If I wanted to write a library, yes. :->


    A library is hardly necessary: one or two functions would do. One might
    even have the option of using the DOM traversal methods.

    > If I know how the markup is generated, I don't see a real benefit in
    > the overhead of using a loop ...


    If the markup was easier to read, write, and generally maintain, I'd
    argue that the overhead would be worth it. I doubt the overhead would be
    that extreme, anyway[1], so it shouldn't be a factor even for
    time-critical code.

    > I would agree that this is quite case-dependent, though.


    Quite. It was the phrase "the best way of formatting" in relation to
    HTML that was my main objection (though obviously my personal dislike
    was also a factor :) ).

    > [markup formatting a la <http://www.w3.org/2000/08/lb2/>]


    [snip]

    > ... it's not a new idea ...


    I realise that, but it doesn't make it any more palatable.

    It might be necessary in some situations (to add to your list: some uses
    of standalone XML), but it isn't in HTML.

    [snip]

    > FWIW, I even find it very readable. ...


    It probably is once one becomes accustomed to it. I can read it as well.
    But, given the choice, I wouldn't.

    Mike


    [1] On a Web forum, someone asked how to improve the performance of a
    DOM traversal function on Pocket PCs. He hadn't profiled the code, and
    the bottleneck was actually in creating and inserting additional elements.

    Even on a resource-strapped mobile device, traversal over a thousand
    nodes should take less than a second (assuming that part of his
    benchmark /was/ accurate), far in excess of what should be necessary.
    Michael Winter, Aug 28, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SJ

    DataList Indentation

    SJ, Nov 3, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,055
    Patrick.O.Ige
    Nov 4, 2005
  2. jacov

    [Fwd: Indentation]

    jacov, Jul 22, 2004, in forum: Java
    Replies:
    0
    Views:
    328
    jacov
    Jul 22, 2004
  3. Daan

    Unwanted indentation

    Daan, Dec 9, 2003, in forum: HTML
    Replies:
    2
    Views:
    446
  4. Jay

    List Indentation

    Jay, Apr 20, 2004, in forum: HTML
    Replies:
    5
    Views:
    534
  5. Jesse B.
    Replies:
    2
    Views:
    187
    Josh Cheek
    Mar 27, 2010
Loading...

Share This Page