PureNews

PureNews is an amazingly sleek and powerful news theme with unlimited color variations.

View full feature list Check out the live demo Buy this theme today

Get in the habit of commenting throughout your design

Posted by on 24th May 2007 Design & Coding 5 comments

There are still a lot of blog themes out there with little or no comments in the design. If your simply uploading the theme and changing the logo then this isn’t something that you will not really have problems with. However, anything beyond that i would strongly advise adding comments throughout your design.

2 minutes adding comments to your templates and coding can save you 10-20 minutes trying to get to grips with your design again at a later date.

This applies to bloggers who are just making small edits to there and also to those who have created their theme from scratch. Try and get in the habit of adding a comment to any significant change to your templates.

When i talk about a significant change i mean something that will not take 2 seconds to find at a later date which is usually the case with the majority of plugins or modifcations you make.

In the past i have been stupidly arrogant and lazy about this kind of thing. If i’ve been working a lot on a site and know the files inside out i have got lazy and left out comments. It’s only when i come back to the design 6 months later and i have’t got a clue where everything works that i kick myself for not commentating the file better.

How do you add Comments

You add comments differently in different programming languages but since the majority of popular blogs are coded with PHP and designed using HTML and CSS, those are the ones i use here.

In HTML the basic code you use is this :

<!-- Add your Comment Here -->

The comment is not displayed publicly – its just a reminder to you about something. For example, some wordpress themes have dozens of css divisions in each template. It can get very confusing sometimes when your not sure which closing div tag belongs to which div

Therefore i always make sure i leave a comment explaining what division its closing like this :

<div id="sidebar">
sidebar code
</div> <!-- End of Sidebar -->

In CSS you can start a comment using /* and end a comment using */.

For example :

/* Sidebar CSS Code */
#sidebar {
width:200px;
float:right;
}

In PHP all you need to do to comment is add // at the start of every line you want to comment.

For example the top of your index.php file could look like

<?php
//
// this is the index.php file
//

Summary

Unless you’ve got a photographic memory, i would strongly advise getting into the habit of adding comments whenever you are working on your files. It really can save you a lot of hassle in the long run.

Good luck,
Kevin

Kevin Muldoon is a webmaster and blogger who lives in Central Scotland. His current project is WordPress Mods; a blog which focuses on WordPress Themes, Plugins, Tutorials, News and Modifications and useful resources such as 101 Places To Find Images For Your Blog Posts.

5 comments - Leave a reply
  • Posted by Techie Buzz on 24th May 2007

    I religiously follow commenting code may it be a simple html or a programming code.

    It really helps others understand what you are trying to do.

  • Posted by EngineerTiat on 24th May 2007

    It's certainly important to "get it right" the first time. Not only for coding but in everything we do. This will save our frustrations later on during troubleshooting.

    Warm regards

    Tiat

    P.S: Choose abundance, http://www.AbundanceLaw.com

  • Posted by Tay on 24th May 2007

    Thanks for the helpful, informative article, Kevin. I will definitely keep all of this in mind!

  • Posted by TechZilo on 24th May 2007

    Didn’t know how to comment PHP code, and got it now. Thanks for the tip, Kev.

    I have found commenting the only way to solve the problem in my blog.

    In my Blogger blog, I would lose track of the hacks and coding I did, and often revert the whole template.

    Now, there’s no such problem!

  • Posted by Brian Heys on 24th May 2007

    I first started programming professionally almost twenty years ago, and quickly learnt the hard way how commenting your code is absolutely essential.

    Nowadays, I automatically put in comments, and sometimes even write comments before I write the code – as a type of 'pseudocode'.

    Ultimately though, I try to write code that is self-documenting, but it's nice to have comments in there for when I forget and come back to something six months later!