45 lines
1.6 KiB
Markdown
45 lines
1.6 KiB
Markdown
|
---
|
||
|
title: >
|
||
|
Custom coding standards and conventions
|
||
|
pubDate: 2023-12-11
|
||
|
permalink: >-
|
||
|
archive/2023/12/11/custom-coding-standards-and-conventions
|
||
|
tags:
|
||
|
- software-development
|
||
|
- php
|
||
|
- drupal
|
||
|
- symfony
|
||
|
- clean-code
|
||
|
---
|
||
|
|
||
|
Open-source projects like Drupal and Symfony have their own published coding standards and conventions.
|
||
|
|
||
|
For example, from [Symfony's coding standards][symfony]:
|
||
|
|
||
|
* Prefix all abstract classes with `Abstract` except PHPUnit `*TestCase`.
|
||
|
* Suffix interfaces with `Interface`;
|
||
|
* Suffix traits with `Trait`;
|
||
|
|
||
|
And from [Drupal's][drupal]:
|
||
|
|
||
|
* Use an indent of 2 spaces, with no tabs.
|
||
|
* Lines should have no trailing whitespace at the end.
|
||
|
* Variables should be named using lowercase, and words should be separated either with uppercase characters (example: `$lowerCamelCase`) or with an underscore (example: `$snake_case`). Be consistent; do not mix camelCase and snake_case variable naming inside a file.
|
||
|
|
||
|
But what about within custom applications?
|
||
|
|
||
|
Do you have your own agreed coding standards and conventions to keep the code consistent?
|
||
|
|
||
|
Do you explicitly follow the published coding standards, customise them, or follow something else?
|
||
|
|
||
|
## Here's the thing
|
||
|
|
||
|
Do you know where to put new custom modules, how to name them and what conventions to follow when writing code?
|
||
|
|
||
|
Do you know where to add a new stylesheet to your theme?
|
||
|
|
||
|
If not, or it's implied, it's worth writing it down and being explicit - either within your project's or company's documentation or publicly.
|
||
|
|
||
|
[drupal]: https://www.drupal.org/docs/develop/standards/php/php-coding-standards
|
||
|
[symfony]: https://symfony.com/doc/current/contributing/code/standards.html
|