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!
Commenting your Code - sodevious.net/2010/02/commenting-your-code/
ResponderEliminarI often need to toggle pieces of code. This is what I use to easily comment and uncomment:
ResponderEliminar/* */
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
}
RT @sodeviousnet: Commenting your Code - sodevious.net/2010/02/commenting-your-code/
ResponderEliminarHey, 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
ResponderEliminarbtw: I use mostly the /**/ commenting-variant