Results 1 to 7 of 7

Thread: quick question

  1. #1
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default quick question

    I hope I found the right place to ask this.

    I see lots of coding where it is indented like this

    <div>
    </div>
    blog {
    margin-left: 8px;

    Doesn't that bloat the script with all those blank spaces being unused?Or does it matter in that regard.

    I think it can make things more confusing but it is done a lot.

    Bud

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Why this

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    		<title>Untitled Document</title>
    		<style type="text/css">
    			#blog { 
    				margin:8px;
    			}
    		</style>
    	</head>
    	<body>
    		<div id="blog">
    			<p>Content</p>
    			<ul>
    				<li>1</li>
    				<li>2</li>
    			</ul>
    		</div>
    	</body>
    </html>

    as opposed to

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    #blog { margin:8px;}
    </style>
    </head>
    <body>
    <div id="blog">
    <p>Content</p>
    <ul><li>1</li><li>2</li>
    </ul>
    </div>
    </body>
    </html>
    The reason is the latter is harder to read and only saves a few bytes at most depending on how big your file is. Almost all connections today will not even not the difference in size it is so small (unless working with an absurdly large file, at that point though you should break the file down).
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    As bluewalrus said, it's all about being readable.

    Take the following example, first formatted:

    Code:
    <div id="content">
    	
    	<div id="posts">
    		
    		<div class="post">
    			
    			<div class="title"></div>
    			
    			<div class="post_content">
    				
    			</div>
    			
    		</div>
    		
    	</div>
    	
    </div>
    Unformatted:

    Code:
    <div id="content">
    
    <div id="posts">
    
    <div class="post">
    
    <div class="title"></div>
    
    <div class="post_content">
    
    </div>
    
    </div>
    
    </div>
    
    </div>
    You can see, as the number of nested divs grow, they become much more difficult to track, that's why the first example is a much preferred way of doing things. In the first example, you know exactly which div you're in straight away.

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,282
    Thanks
    97
    Thanked 104 Times in 102 Posts

    Default

    While these ways are the preferred ways to code I find that it is best to code in a way that makes sense to you. Make sure that when you do write a script to do so in such a way that when you go back to it you can easily make sense of it.

    I have my own style of indentation that I use, which is somewhat my own and I tend to use some form of notation at times and I also use dividers to separate one element of my script with another.

    How do you mean it makes things more confusing?
    To choose the lesser of two evils is still to choose evil. My personal site

  5. #5
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default Thanks everyone!

    I just noticed that my post does not show up correctly.

    But most of you figured out what I was talking about anyway.Thats cool!

    I guess that due to the fact that I don't do much scripting it makes a difference.

    Though I always wondered if there was a reason or concept I was unaware of that most people were applying.

    As far as confusing, so far I need to just start from the left and seperate each section from each other when possible.

    I do think putting comments in as I work is a great idea that can help when editing is done if a web page is large.

    I have been working on a rather large page and editing is becoming more difficult but thankfully I am just putting the finishing touches on it -lol

    Bud

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    HTML, at least for an experienced designer, is generally easy to read. Using some sort of tabbing is always a good idea, at least not just typing everything on one line or something like that. Using line breaks and tabs to group things visually makes it faster to understand the code and helps to keep everything organized. Beyond that, I pretty much agree with james that you should do what makes sense to you. In HTML, I'm not sure comments are really needed. Marking sections with them (like <!--images section-->) might make make, but beyond that it seems extraneous at least for a fairly experienced designer, as I said. (Of course if you are still learning some of this stuff and adding comments helps, go ahead. There's nothing wrong with that, except, in my opinion, slightly messy course code with extra comments-- I don't like the way comments are formatted in HTML for one thing.)

    Applying this more generally to other languages like PHP (I spend most of my time coding PHP) the same applies: tabs are useful, and in a language like PHP (really anything aside from HTML, which is just markup, not really programming) consistent tabs are crucial.
    Regarding James's comment about using your own style: that's fine. BUT... make sure that if you ever plan to work with someone, or sell your code to someone who might later need to edit it, that it's close enough to standard that someone can work with it.
    I tend to code in a slightly unconventional way, so I need to watch out for that when I'm working with others. A great way to make it easier for them is to use comments. I like comments in PHP because they don't get in the way too much and they're hidden in the final output. And in PHP is can be difficult to remember what something is doing, unlike HTML that is generally surface-oriented.


    A quick summary:
    1. Always use tabs and line breaks to organize code. (In any way you want as long as it is clear.)
    2. Use comments when needed. Use lots of comments. But don't use comments when it is clear from the code itself.

    I hope that helps some.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default thanks for some insightful opinions

    I try and use as little notes/comments as possible.

    The question mostly pertains to some pages that go back and forth from left to right numerous times and I just wondered why.

    I understand each post as a valid answer-you all imply it is as each individual needs/wants or prefers.And as usual that makes sense.

    I don't write much stuff ( html and css at most) mostly due to the fact I have never learned php,cgi or any other scripting.They look daunting to me and I usually learn better/faster from example.Reading does not do it for me with this type of thing.

    I have had issues just with what I am doing to date sometimes coming accross times when I am completely baffled why something won't work.As in a post in the dd scripts about a page with three rss display boxes where only one shows-the other two don't ( I have lost sleep due to this problem and still can't figure out what is wrong.

    Anyway thanks for the opinions and help

    Bud

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •