# Moodle Docs: Coding Guidelines

## Moodle Coding Guidelines

## General Rules

1. All files should use the .php extension.
2. All existing copyright notices must be retained. You can add your own if necessary.
3. Each file should include the main config.php file.
4. Each file should check that the user is authenticated correctly, using require_login() and isadmin(), isteacher(), iscreator() or isstudent().
5. All access to databases should use the functions in lib/datalib.php whenever possible - this allows compatibility across a wide range of databases. You should find that almost anything is possible using these functions. Any other SQL statements should be: cross-platform; restricted to specific functions within your code (usally a lib.php file); and clearly marked.
6. All strings should be translatable - create new texts in the "lang/en" files and call them using get_string() or print_string().
7. All help files should be translatable - create new texts in the "en/help" directory and call them using helpbutton().

## Coding Style

1. Don't use tabs at all. Use consistent indenting with 4 spaces.
2. Braces must always be used for blocks of code (even if there is only one line). Moodle uses this style:

   if ($quiz->attempts) {
   if ($numattempts > $quiz->attempts) {
   error($strtoomanyattempts, "view.php?id=$cm->id");
   }
   }

3. more to come here .... this document is not nearly finished yet!

Moodle Documentation

Version: $Id: faq.html,v 1.6 2003/03/30 13:54:28 moodler Exp $