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

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #15) by minnieadkins on Oct 31 2005, 06:48 PM. (Line Breaks Removed)
Comments make the code. HTML comments aren't very widely used, but they do help, especially if you plan on modifying your layout in the future. It's also a good practice to comment the end of your functions (php, c++, java, etc) and the beginning to display what they actually do. While loops, foreach loops, if statements all pose a threat of error. All it takes is overlooking that one ... read more.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > HTML, XML and other Markup Languages

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

vujsa
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:
Click to view 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

 

 

 


Reply

miCRoSCoPiC^eaRthLinG
cool.. good followup on that Commented Coding article. smile.gif

Reply

vujsa
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

 

 

 


Reply

jcguy
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?

Reply

vujsa
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

Reply

Spog
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.


Reply

vujsa
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

Reply

ChronicLoser
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 ^_^

Reply

moonwitch
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!

Reply

h3lium
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

Reply

Latest Entries

minnieadkins
Comments make the code. HTML comments aren't very widely used, but they do help, especially if you plan on modifying your layout in the future. It's also a good practice to comment the end of your functions (php, c++, java, etc) and the beginning to display what they actually do. While loops, foreach loops, if statements all pose a threat of error. All it takes is overlooking that one little '}' and there you have it. ERROR. Good advice on the comments, although I personally think you can have too many comments. Keep it informative and direct. Don't make half your document comments. =/

For a nice free text editor, I recommend HTMLKit from Chami. When you put in your javascript it automatically puts in the comment to keep older browsers from reading your script. It's a very nice editor, and very customizable. Lots of plugins for php as well. I recently used notepad++ and it's pretty good for all kinds of languages, and you can minimize your blocks effectively.

Reply

twitch
QUOTE(guy @ Oct 29 2005, 07:04 PM)
Although a lot of people are against validation, it makes us better at designing. By validating your website and routing out all of the errors, we can make better and more usable sites. Something that XML/XHTML was developed for.

Vujsa, this is a very good thread. However, I believe you failed to mention WHY we put the contents of a script in comment tags. The answer is that older browsers (IE 3.0) may not be able to perform the actions of the script, and would display it as text. By putting it in comment tags, it is kept from displaying, but the browser still reads and processors the script.
*


Sorry vujsa, I failed to see that you did explain, in brief, why comment tags are used in <script> tags.

Reply

Logan Deathbringer
Although I don't comment my HTML like I should, and must admit that I pay the price later on...lol. Anyone who is just starting out should comment their HTML and any scripting/programing they do. As stated by Vujsa and others this helps with revisions later on, ALSO it helps when giving a friend a copy to look over when you need help troubleshooting a page or whatever so that they can tell at a glance what you were trying to do in a certin section without haveing to pull out a 5 lb. 4 ring binder full of coding notes to track down some obscure and rarely used, by the troubleshooter, bit of code tongue.gif

Reply

Quatrux
I almost never use comments in html unless i want to make a comment for myself.. the output php shows me as html is usually different and stuff, i never watch it, only to make valid and clean in the making period, and later when everything runs smooth i never watch the source.. maybe it is due to my html is never being very complicated, i just see it with my eyes as a web browser biggrin.gif but comments due help, even if it is said: "a real programmer does not need comments, the code is obvious to him" but sometimes the codes i wrote say a year back is not so understandable, that is why I started to write comments and another reason is because i might work with other people who will edit/write it too.

Reply

vizskywalker
Also, if you are using XHTML, be sure to read the documentation on how to do comments. In XHTML 1.0 Strict, putting HTML comments around code inside javascript tags is invalid, and will cause lack of validation. Instead, you need to use the CDATA comments.

~Viz

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Pages: 1, 2
Recent Queries:-
  1. how to make comment tags - 27.31 hr back. (1)
  2. how to make an html comment - 28.70 hr back. (1)
  3. how to make comments in xhtml - 33.85 hr back. (1)
  4. how to make comments alignments in html delphi - 42.35 hr back. (1)
  5. how to make a good comment - 24.13 hr back. (2)
  6. how to make comment in html - 70.76 hr back. (1)
  7. how to create comments on html - 218.04 hr back. (1)
  8. how do make comments in html - 228.97 hr back. (1)
  9. how to create comment posting in html - 273.37 hr back. (1)
  10. html how to make a comment - 275.61 hr back. (1)
  11. commenting html - 278.77 hr back. (1)
  12. html how to make comments - 294.97 hr back. (1)
  13. how to make comments with html - 327.64 hr back. (1)
  14. how to do a html comment - 346.58 hr back. (1)
Similar Topics

Keywords : good, comments, make, good, html, commenting, makes, html, easier, write

  1. Basic Html Tutorial
    Made it myself, hope you like it. (1)
  2. Html Basic Tutorial
    <!-- For beginners only --> (9)
    Knowledge HTML stands for H yper T ext M arkup L anguage. You cannot create an HTML file
    using a rich-text editor, such as Microsoft Word or Wordpad. HTML To write a basic HTML, you will
    need to start with this: CODE The html > tag tells the browser that this is an HTML page.
    To close any tag, the same tag will be repeted but with the "/" sign. For example, CODE   
         Page title    Did you notice the /title >, /head > & /html > tags? That's how we
    close the tag. The HEAD > Tag A head > tag will include the meta >, titl....
  3. HTML Tags
    Ever wondered what a HTML tag was (4)
    Many people that i have met have mentioned HTML to me without really knowing what it really means.
    Because of this i thought that maybe it would be a good idea to compile a tutorial for everyone to
    read. When i listen to people talking about HTML; they never seemed to know what a HTML tag was so
    that is what i will focus on here. ------------------- Some people who use HTML may notice that I
    place the tags below in the order they appear in a document. Most people who use HTML know the tags
    which no HTML document can do without. Those are: = this is the tag which ev....
  4. Quick Html!
    Three of the coolest scripts! (3)
    Table of contents: -Meta -Cursor -Icon -Animated Title Bar (Must see!) META Meta tags is
    one of the most important things you need to know about programming. It truly will help you is more
    ways then you can imagine. First off you may be wondering what a meta tag is. A meta tag is a simple
    few lines of code that you put in the header of your document to describe it. If you do this
    correctly you can get search engines (including Google) to add your website. There are a few things
    you want to keep in mind when your making your meta tags. Make sure that you stay on ....
  5. HTML 102 - Web Design For Beginners
    More Basic HTML Writing (6)
    HTML 102 - Web Design For Beginners More Basic HTML Writing This will be part two of a
    multi-part HTML tutorial. Please don't post advanced HTML replies to this article. This
    tutorial is specifically written for beginning HTML writers. Requirements: Software: Web Browser,
    HTML Editor. Knowledge: HTML 101 - Web Design For Beginners. Skills: Ability to press the
    keys on the keyboard. So you have read and understood HTML 101 - Web Design For Beginners and
    you want to learn more. So far we have talked about a very basic web page. Black on white an....
  6. HTML 101 - Web Design For Beginners
    Absolute Basic HTML Writing (7)
    HTML 101 - Web Design For Beginners Absolute Basic HTML Writing This will be part one of a
    multi-part HTML tutorial. Please don't post advanced HTML replies to this article. This
    tutorial is specifically written for beginning HTML writers. Requirements: Software: Web
    Browser, HTML Editor. Skills: Ability to press the keys on the keyboard. Any web browser will
    work as long as it can open files saved on your hard drive. -> Netscape and Internet Explorer are
    both free and easy to use. Any HTML editor will work as long as it is an HTML editor and not a web....
  7. Converting HTML over to XHTML
    Crossing over to the darkside (13)
    Allow for alterations Well, I've just had to convert another HTML 4.01 Transitional website
    over to XHTML (eXtensible HyperText Markup Language) 1.0 Transitional, I will later on convert over
    to XHTML 1.0 Strict as soon as I write the CSS (cascading stylesheet) file for it but it had to be a
    quick update and removing all presentational elements and placing them in a CSS file is not quicker
    than just altering some tags. So this is where I got the idea to write a How to Convert HTML over
    to XHTML . Let's begin I'm having trouble knowing where to start ....

    1. Looking for good, comments, make, good, html, commenting, makes, html, easier, write






*SIMILAR VIDEOS*
Searching Video's for good, comments, make, good, html, commenting, makes, html, easier, write
advertisement




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