Commenting your Code

When learning how to code in various languages, it often times helps to know the proper way to comment out certain items. If you don’t already know what it means to add a ‘comment’ to the code, it can be little notes for you, or others who are going to read it. They can also be used to block something out, it’s stopping a certain piece of code from it being read by the browser, or whatever have you. It’s also smart to organize your code with comments. For instance, because you can’t add selectors to an ending div class, you can add a comment to let you know which div you’re ending. Lets start, shall we?

HTML

<!-- HEADER START -->

Hints: It’s best to avoid using ‘ – ‘ (the dash) to keep things from getting confusing, and use spaces before/after the dashes.

CSS

/* clear div to fix errors */

Same concept for HTML, adding notes or blocking off code. Can be used inside or in-between elements.

PHP

/* WP Post (many lines)*/

// Start the loop (1 line)

There are two kinds of comments you can use in PHP, the ‘/* */’ being for multiple lines of code, and ‘//’ for one line.

I hope that you learned something new! Enjoy!

Written By:

Nicole Dominguez

Nicole Dominguez is a 16 year old blogger who loves all things creative, with a passion for web design.
This entry was posted in Tutorials and tagged , , , , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Posted February 7, 2010 at 4:32 pm | Permalink

    I often need to toggle pieces of code. This is what I use to easily comment and uncomment:

    /* */
    This code can be quickly commented out by removing one character.
    Now it is not commented out.
    /* */

    /* *
    This code can be quickly uncommented by adding one character.
    Now it is commented out.
    /* */

    So just by adding/removing the “/” (slash) character the code is commented/uncommented.
    If it doesn’t make any sense, copy it and paste it somewhere where the syntax is highlighted. The comments will stand out better.

    Another thing… if you have a large piece of code (PHP or JavaScript) that needs to be commented out but it already has /* this type of comments */ in it, you won’t be able to wrap it between /* and */ if you wanna turn it off.
    Instead, you can wrap it in an if statement that’s always false:

    if ( 1==2 ) {

    this would be some code that won’t be executed
    but we still have it here, in case we decide we do need it
    /*
    it can also have comments
    */
    more code

    }

  2. Posted February 17, 2010 at 7:50 pm | Permalink

    Hey, yeah it’s really important, to comment your code, if you’re opening a project which you finished serveral months ago, and I you did not comment your code, It’s a mess to clean up the code and to find yourself back in the code

    btw: I use mostly the /**/ commenting-variant

  3. Posted April 25, 2010 at 10:29 pm | Permalink

    Just to give a little history, the block comment type (/* */) was all you had in C. Perl came up with inline comments, they used #. C++ copied that idea, but also kept block comments, and so you have block (/* */) or inline (//) comments. PHP is based off of C/C++ so you have of course all the C++ commenting, plus they allow Perl style (#).

    @Stefan If you join a group of programmers you’ll learn that the proper way is to block out code, not comment it out.

    Commented code saves your life, so always use it, even when it’s obvious what it does.

3 Trackbacks

  1. [...] here to see the original: SoDevious.Net » Commenting your Code Share and [...]

  2. By Nicole Dominguez on February 7, 2010 at 3:10 pm
  3. By Nicole Dominguez on February 7, 2010 at 4:47 pm

    RT @sodeviousnet: Commenting your Code – http://sodevious.net/2010/02/commenting-your-code/

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

All Rights Reserved. © Nicole Dominguez, Unless Stated Otherwise.

Google PageRank Checker Postcards Exchange online counter Powered by FeedBurner