Welcome Guest ( Log In | Register )



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Good Comments Make Good Html., Commenting makes HTML easier to write.
vujsa
post Feb 24 2005, 01:03 AM
Post #1


Absolute Newbie
Group Icon

Group: Admin
Posts: 888
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714



Good Comments Make Good HTML.
Commenting makes HTML easier to write.

This is a spin off from another article I wrote entitle Good Comments Make Good Scripts. While the code is different, the concepts for comment are the same.
Enjoy!

Disclaimer!
This tutorial is intended to be used to show the benefites of commenting your HTML in order to write clean, easy to read code. For the purpose of this tutorial, HTML, XML, XHTML validating is not taken into consideration. While I will make an effort to point out non-standardized code, validation has never been my priority and I'll probably miss a few things. Always run your HTML through an HTML validater to check for compatability issues.


Reasons for commenting HTML:
    [/tab]- Makes your code easier to trouble shoot.
[tab]- Add a friendly reminder of things you wanted to include in your page.
    [/tab]- Allows you to save information about the page without showing the general public.
[tab]- Provides a way of giving yourself credit for creating a nice page.
    - Used as instructions for JavaScript and other client side script usage.

Getting Started!
-------------------------------------------------------------------
An HTML comment tag is quite simple, everything inside the tag is hidden from the browser and is considered to be the comment.
The HTML comment tag is:
CODE
<!-- -->


Example with a comment:
CODE
<!-- Here is a comment! -->


Example of a multi-line comment:
CODE
<!-- I would like take this oppurtunity to descript the color of the sky.
The color of the sky is a unique shade of the color blue.
Unless of course there is overcast and then its more like gray.
Then again in the fog evreything is white.
Appearently the sky is multicolored! -->


Now lets talk about when and where to comment yout HTML.

The first place I like to add a comment in a web page is at the beginning of a table.
Example:
CODE
<!-- Start table 1 here - 3 rows high and 4 columns wide -->
<TABLE BORDER="1">
<TR>
...


Another really good use for a comment in a table is when a cell spans multiple rows or columns.
Say that you have a table that is 4 rows and 4 columns and you want one really large cell in the middle.
Attachment:

Comments will help you keep track of where cells used to be.
Example:
CODE
<!-- Table 1 - 4 rows high and 4 columns wide -->
<TABLE BORDER="1">
   <TR>
       <TD>
           Cell 1-1
       </TD>
       <TD>
           Cell 1-2
       </TD>
       <TD>
           Cell 1-3
       </TD>
       <TD>
           Cell 1-4
       </TD>
  </TR>
  <TR>
       <TD>
           Cell 2-1
       </TD>
       <TD COLSPAN="2" ROWSPAN="2">
           Cell 2-2
       </TD>
        <!-- Cell 2-3 would have been here -->
       <TD>
           Cell 2-3
       </TD>
   </TR>
   <TR>
      <TD>
           Cell 3-1
       </TD>
        <!-- Cell 3-2 would have been here -->
        <!-- Cell 3-3 would have been here -->
       <TD>
           Cell 3-4
       </TD>
   </TR>
   <TR>
      <TD>
           Cell 4-1
       </TD>
       <TD>
           Cell 4-2
       </TD>
       <TD>
           Cell 4-3
       </TD>
       <TD>
           Cell 4-4
       </TD>
  </TR>
</TABLE>
<!-- End table 1 here -->

I use this frequently as I tend to get confused when I start spanning cells.

Occasionally I have very lengthy forms that I need to comment in order to keep track of what's what.
Example:
CODE
........
<INPUT TYPE="TEXT" NAME="Var126" SIZE="25"> <!-- This is the 126th input variable for this form -->
........


Comments are great for saving places for all of our content.
For example, say you have an advertiser with a banner and just below his banner you have room for one more banner, just comment that this is where you can place a new add.
Example:
CODE
<!-- Start Foo.com's Banner Code Here-->
<A HREF="http://www.foo.com/foo_sale.html"><IMG SRC=="http://www.foo.com/foo_sale.gif"></A>
<!-- End Foo.com's Banner Code Here -->

<!-- To Quit Losing Money Place Advertisement Here!;) -->

<H1><CENTER>My Title Here</CENTER></H1>


This works great for code you don't know how to write yet as well.
Example:
CODE
Fill in the form below to order your free money:<BR>
<!-- Use some of my money surplus to learn how to add an HTML form here! -->

If you have any questions <A HREF="mailto:jdoe@foo.com">Email Me!</A><BR>


Okay here's an example of what didn't work:
CODE
<FONT COLOR="RED">  <!-- Yellow font does not work here you already tried it three times! -->


Another method I use to help keep track of the flow of HTML is indenting.
Example:
CODE
<HTML>
   <HEAD>
       <TITLE>
           My Title.
       </TITLE>
   </HEAD>

   <BODY>
       Body content here.
   </BODY>
</HTML>


See how easy it is to check if all of your closing tags are present.
This is great if you have tables inside of tables, but will always make reading the code a lot easier.

You may have noticed that all of my tags use uppercase type. I have found that this makes picking the tags out from all of the content text much easier. When I learned HTML, tags were always like this but now validation requires lowercase type as I understand it. You will have to decide for yourself how best to write your code but I suggest that you keep in mind the possibility that someday you may need to convert your HTML to another markup language.

Tells us about your suggestions for commenting.

Happy coding, cool.gif
vujsa
Attached File(s)
Attached File  table.JPG ( 5.56k ) Number of downloads: 94
 
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post Feb 24 2005, 11:17 AM
Post #2


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411



cool.. good followup on that Commented Coding article. smile.gif
Go to the top of the page
 
+Quote Post
vujsa
post Feb 25 2005, 04:06 AM
Post #3


Absolute Newbie
Group Icon

Group: Admin
Posts: 888
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714



Something I touched on breifly in this article but doesn't warrant its own tutorial is commenting client side scripting.

I'll specify JavaScript.

To begin with, you should place your JavaScripts inside an HTML comment tag.
Example:
CODE
<script LANGUAGE="JavaScript">
   <!--
   function foo() {
       ...
       ...
   }
   -->
</SCRIPT>
This is done to hide the script from browsers that don't support JavaScript. The practice of hiding the script is fast becoming pointless due to the fact that any decent web browser is JavaScript capable. I suggest that you continue hiding the code until Microsoft Windows is provided free to everyone. biggrin.gif

Next Place HTML comments around your scripts.
Example:
CODE
<!-- Start Your JavaScript Here! -->
   <script LANGUAGE="JavaScript">
       <!--
       function foo() {
         ...
         ...
       }
       -->
   </SCRIPT>
<!-- End Your JavaScript Here! -->


Finally Place script comment in your scripts.
Example:
CODE
<!-- Start Your JavaScript Here! -->
   <script LANGUAGE="JavaScript">
       <!--
       function foo() {     // Same Double Slash Comment Tag As In PHP!
         ...
         ...
       }    // End Function Here!
       -->
   </SCRIPT>
<!-- End Your JavaScript Here! -->


Happy coding, wink.gif
vujsa
Go to the top of the page
 
+Quote Post
jcguy
post Feb 25 2005, 12:54 PM
Post #4


Premium Member
Group Icon

Group: Members
Posts: 382
Joined: 5-September 04
Member No.: 255



Can commenting in the coding be done in php and perl scripts as well? I remembered vaguely that it can be done in php and perl scripts, but I think the way of commenting will be different. Does this code:

<!-- commenting -->

works in php and perl too?
Go to the top of the page
 
+Quote Post
vujsa
post Feb 25 2005, 10:51 PM
Post #5


Absolute Newbie
Group Icon

Group: Admin
Posts: 888
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714



QUOTE(jcguy @ Feb 25 2005, 07:54 AM)
Can commenting in the coding be done in php and perl scripts as well? I remembered vaguely that it can be done in php and perl scripts, but I think the way of commenting will be different. Does this code:

<!-- commenting -->

works in php and perl too?
*



Actually, I wrote another topic just for that. I have a link at the beginning of this tutorial.

Here it is again:
Good Comments Make Good Scripts.
This is specifically for PHP but Perl is touch on as well.

Happy coding, cool.gif
vujsa
Go to the top of the page
 
+Quote Post
Spog
post Mar 13 2005, 03:58 AM
Post #6


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 10
Joined: 13-March 05
Member No.: 3,023



QUOTE(vujsa @ Feb 25 2005, 06:51 PM)
in fact, i think in php we gotta comment with
// comments here
but im not sure if its in php.

Go to the top of the page
 
+Quote Post
vujsa
post Mar 16 2005, 12:22 AM
Post #7


Absolute Newbie
Group Icon

Group: Admin
Posts: 888
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714



Actually, php allows multiple comment tags.

All of the following comment tags work in php:
// JavaScript single line comment tag.
/* JavaScript multiple line comment tag. */
# Shell style comment tag.

See Also -> Good Comments Make Good Scripts.

vujsa
Go to the top of the page
 
+Quote Post
ChronicLoser
post Mar 16 2005, 12:42 AM
Post #8


Premium Member
Group Icon

Group: Members
Posts: 240
Joined: 13-November 04
From: Arizona
Member No.: 1,356



hmm...i agree that comments are useful in html...but I think it's much more important in scripting (example: java, javascript, php, etc, etc). With html, it usually doesn't get so convoluted to a point where you absolutely need/require comments and such...

but I completely agree with you, vujsa. Comments do make things simpler ^_^
Go to the top of the page
 
+Quote Post
moonwitch
post Mar 16 2005, 03:22 AM
Post #9


Demonic Enforcer
Group Icon

Group: [HOSTED]
Posts: 597
Joined: 2-March 05
From: Belgium
Member No.: 2,861



QUOTE(vujsa @ Feb 24 2005, 02:03 AM)
You may have noticed that all of my tags use uppercase type.  I have found that this makes picking the tags out from all of the content text much easier.  When I learned HTML, tags were always like this but now validation requires lowercase type as I understand it.  You will have to decide for yourself how best to write your code but I suggest that you keep in mind the possibility that someday you may need to convert your HTML to another markup language.

Tells us about your suggestions for commenting.

Happy coding, cool.gif
vujsa
*


I used to write my html in uppercase all the time as well, for the same reason you've just touched. To find the actual code easier smile.gif BUT I've now switched to lowercase, not because of the validation (heh, I hardly ever use it tongue.gif) but because xml (and I think XHTML) both require lowercase tags.

My biggest help in writing HTML is basically good indentation. It's one of my pet peeves, to look at horrid code with crappy indentation. For example, someone did write the code in notepad, but prefered "Times New Roman" as font because it looked better than Courier, and they used tab. It will look horrible in code when you do use a fixed width font. I have to admit it, I don't use Courier, but I do use another fixed width font for coding wink.gif (ProggyCleanTT or Anonymous I think)

Anyhow, good tutorial vujsa!
Go to the top of the page
 
+Quote Post
h3lium
post Aug 10 2005, 07:07 PM
Post #10


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 10
Joined: 10-August 05
Member No.: 7,750



for simple pages, i always find it easier to not use comments, because they usually don't amount to much, but for larger complex projects that involve a lot of coding, commenting is essential for later revisions and modifications
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Converting HTML over to XHTML(13)
  2. HTML 101 - Web Design For Beginners(7)
  3. HTML Tags(4)
  4. Html Basic Tutorial(9)
  5. Basic Html Tutorial(1)


 



- Lo-Fi Version Time is now: 14th October 2008 - 03:49 AM