# Standards of Coding

We know how much consistency is important, especially if we are writing open-source code. This is because the source code is used by a lot of people and everyone keeps an eye on it. Hence, these people find bugs and take corrective actions to fix them.

Because of these reasons, when you are writing a theme, a plugin, or a key patch, you must follow the listed guidelines when you are writing something for QloApps.They are the ones that the developers of QloApps stick to and when you follow them then there is a guarantee that you can easily integrate your code with QloApps.

In brief, to keep the code easy to read and maintain it is important to have code consistency.

The standards, conventions, and guidelines for QloApps development are as follows:

# SQL guidelines

For Table

  1. Table names should begin with the "DB_PREFIX" prefix.
  2. Table names should have the exact ditto name as the object they reflect: "prefix_cart".
  3. Table names have to be singular: "prefix_order".
  4. Save the data for languages has in a table that is named exactly the same as the object's table, and with the "_lang" suffix: "prefix_product_lang".

For SQL queries

  1. Write keywords in uppercase.
 SELECT `firstname`
 FROM `'._DB_PREFIX_.'customer`
  1. Always use Back quotes ("`") around SQL field names and table names.
   SELECT p.`foo`, c.`bar`
   FROM `'._DB_PREFIX_.'product` p, `'._DB_PREFIX_.'customer`  
  1. Name Table aliases by taking the first letter of each word, and must be lowercase.
   SELECT p.`id_product`, pl.`name`
   FROM `'._DB_PREFIX_.'product` p
   NATURAL JOIN `'._DB_PREFIX_.'product_lang` pl
  1. Whenever there is a conflict between table aliases, the second character is also used in the name.
   SELECT ca.`id_product`, cu.`firstname`
   FROM `'._DB_PREFIX_.'cart` ca, `'._DB_PREFIX_.'customer`
  1. Create a new line for each clause.
   $query = 'SELECT pl.`name`
   FROM `'._DB_PREFIX_.'product_lang` pl
   WHERE pl.`id_product` = 17';
  1. It is forbidden to make a JOIN in a WHERE clause.