Background Image
Web
Development
Tools
Tool...
49 Projects
Web Development Project
Web
Development
Project
Programming Guide: Code guidelines
Creator:Graphix
Last edit:2010-11-02 19:58:29

When writing your code (and especially if it's open-source), it should be written properly. A few things you should consider using/adding when programming.

  • Comments - When writing your code, add comments to every piece your write. Adding comments after writing the code can be confusing, as you can forget what it exactly does. Also, if you need a modification of the code in a later stadium, having comments that lead you through every step of the program will be extremely handy.

  • Script description - At the top of each function/entire script you should write what it does, what arguments it takes, and what it echo's or returns

  • Indent and spacing - Indenting and correctly spacing the code is very important for the readability. For example, the following JavaScript function is really difficult to read:
    Code Snippet (Syntax highlighted) - Toggle Wrap

    function MyFunction() {
    var x = 0;
    var i = 2;
    if (x == 1) {
    if (i < 0) {
    x++;
    } else {
    i--;
    }
    x--;
    }
    x++;
    }


    And could be corrected to:

    Code Snippet (Syntax highlighted) - Toggle Wrap

    function MyFunction() {

    var x = 0;
    var i = 2;

    if (x == 1) {

    if (i < 0) {

    x++;

    } else {

    i--;

    }

    x--;

    }

    x++;

    }


    However, every programmer has its own style, and the above is just an example on how you could write your code.

  • Syntax Highlighting Editor - It is advised to use an editor that highlightes the syntax, it makes finding typo's and problems in your code alot easier. I composed the following list of proper (free!) editors:

    • Notepad++ - Click here to visit their website
      A free (as in "free speech" and also as in "free beer") source code editor and Notepad replacement that supports several languages. Running in the MS Windows environment, its use is governed by GPL License.

    • Notepad2 - Click here to visit their website
      A fast and light-weight Notepad-like text editor with syntax highlighting. This program can be run out of the box without installation, and does not touch your system's registry.


  • Security - Make your project safe should be one of your top priorities. I have composed a few tips to help you make your project secure:

    • PHP - Make sure you do not have the register_global option on the php.ini on the value "YES", as this can be a huge security risk if you do not want the visitor to set variables in your script.

    • PHP/ASP.NET - It is recommended to clean every value you have received from a form (POST or GET), for example in PHP:

      $my_var = htmlentities(addslashes($_POST['my_var']));




Comments
Latest news
New project: Math Quiz
2010-11-09 18:07:48
Read more...

New project: Custom Messagebox
2010-11-06 19:10:50
Read more...

New project: Visitor Counter
2010-11-01 21:39:04
Read more...

New project: Image Editor
2010-11-01 21:37:27
Read more...

New project: Image Generator
2010-11-01 21:33:05
Read more...

Projects Contact © 2010 WDP - All rights reserved Terms and Conditions Log in