========================================== Rule: Use Spaces for Indentation, Not Tabs ========================================== **Rule Code:** ``CV12`` **Name:** ``spaces_not_tabs`` Overview -------- In SQL and programming in general, it is a best practice to use spaces for indentation instead of tabs. While both spaces and tabs can be used to indent code, spaces provide more consistent formatting across different environments, editors, and systems. Using spaces for indentation ensures that the code appears the same regardless of the viewer’s settings and avoids issues with misaligned or uneven code that can result from the use of tabs. Explanation ----------- Anti-pattern: Using Tabs for Indentation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Using tabs for indentation can lead to inconsistent formatting because different editors and environments interpret tabs differently. A tab might be displayed as two, four, or even eight spaces depending on the configuration of the user's editor, making it difficult to maintain a consistent look and feel for the code. This can lead to confusion, especially when multiple developers work on the same codebase. **Example of Using Tabs for Indentation (Anti-pattern):** .. code-block:: sql SELECT * FROM orders JOIN customers ON orders.customer_id = customers.id; In this example, tabs are used for indentation, which can result in inconsistent alignment depending on the viewer's editor settings. Best Practice: Use Spaces for Indentation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To ensure consistent formatting and readability across different environments, spaces should be used for indentation. Most coding standards recommend using spaces because they provide a uniform way of displaying indents, regardless of the editor settings. **Refactored Example Using Spaces for Indentation (Best Practice):** .. code-block:: sql SELECT * FROM orders JOIN customers ON orders.customer_id = customers.id; In this refactored example, spaces are used for indentation, ensuring that the code appears consistent across different editors and systems. Conclusion ---------- Using spaces for indentation instead of tabs ensures that SQL queries are consistently formatted, readable, and maintainable. This practice reduces the likelihood of formatting issues caused by different tab width settings in various editors and environments, leading to cleaner and more professional code. Groups: ------- - ``all`` - ``convention``