display | more...
A common mistake made by much starting programmers is that they don't take the time to keep their code clean. When they, or someone else for that matter, look at their code a little while later, for example because they want to improve their script, they will have a hard time figuring out which parts do what. That's why I am going to give you a few tips to keep your code clean.

1. Use empty lines. Use empty lines to seperate parts of the script that have different functions. Use empty lines before control structures. Use them as much as possible. It makes the file easier to read and understand.

2. Use tabs to indent the parts of the script that are within control structures. For example:

If ($action = "view") { 
	echo "Currently viewing $file"
}

3. Use comments to describe everything the script does. For example:

// If the user is viewing a file, print the filename. 
If ($action = "view") { 
	echo "Currently viewing $file"
}

4. Use good, descriptive names for your variables. For example: $filename, instead of: $f. Stick to one naming style.

5. Decide beforehand what case your variables use. Because variable names are case sensitive, that will save you a lot of time when you try to figure out what variable you used somewhere else in the script. Format all your variables lowercase, uppercase or however you want to format them. Stick to one style.

Note: I noded this with the php language in mind, since that's the language I programmed it in, but it's suitable for other languages as well. Just ignore the php-only commands used in the examples.

Log in or register to write something here or to contact authors.