- Magento 2 Developer's Guide
- Branko Ajzele
- 396字
- 2021-07-30 09:53:23
Coding standards
Coding standards are a result of conventions designed to produce high-quality code. Adopting certain standards yields better code quality, reduces the time taken to develop, and minimizes maintenance cost. Following coding standards requires knowing the standards in question and meticulously applying it to every aspect of the code that we write.
There are several coding standards that Magento abides by, such as the following ones:
- The code demarcation standard
- The PHP coding standard
- The JavaScript coding standard
- The jQuery widget coding standard
- The DocBlock standard
- JavaScript DocBlock standard
- The LESS coding standard
The code demarcation standard speaks of decoupling HTML, CSS, and JS from PHP classes. By doing so, the backend-related development stays unaffected by frontend development and vice versa. This means that we can make business logic changes without fearing a broken frontend.
The PHP coding standard refers to PSR-1: Basic Coding Standard and PSR-2: Coding Style Guide that are described at on PHP filenames, class names, namespaces, class constant, properties, and methods. PSR-2 extends the PSR-1 by touching upon the actual inners of a class, such as spaces, braces, method and properties visibility, control structures, and so on.
The JavaScript coding standard is based on the Google JavaScript Style Guide found at https://google.github.io/styleguide/javascriptguide.xml. This coding standard touches on the JavaScript language and coding style rules. It is a lot like PSR-1 and PSR-2 for PHP.
The jQuery widget coding standard is flagged as mandatory for Magento core developers and recommended for third-party developers. It goes without saying how important jQuery UI widgets are in Magento. The standard describes several things, such as widget naming, instantiation, extension, DOM event bubbling, and so on.
The DocBlock standard touches on the requirements and conventions for the addition of inline code documentation. The idea is to unify the usage of code DocBlocks for all files regardless of the programming language in use. However, a DocBlock standard for that particular language may override it.
The JavaScript DocBlock standard relates to the JavaScript code files and their inline documentation. It is a subset of Google JavaScript Style Guide and JSDoc, which can be found at http://usejsdoc.org.
The LESS coding standard defines the formatting and coding style when working with LESS and CSS files.
Note
You can read more about the actual details of each standard at http://devdocs.magento.com, as they are too extensive to be covered in this book.
- Java程序設(shè)計(jì)(慕課版)
- Learning Apex Programming
- DevOps入門與實(shí)踐
- 新編Premiere Pro CC從入門到精通
- Python數(shù)據(jù)分析(第2版)
- 網(wǎng)店設(shè)計(jì)看這本就夠了
- Building Minecraft Server Modifications
- Microsoft System Center Orchestrator 2012 R2 Essentials
- GameMaker Essentials
- Scratch趣味編程:陪孩子像搭積木一樣學(xué)編程
- R Data Science Essentials
- 零基礎(chǔ)學(xué)Python編程(少兒趣味版)
- 青少年學(xué)Python(第2冊(cè))
- Puppet:Mastering Infrastructure Automation
- C# 7.1 and .NET Core 2.0:Modern Cross-Platform Development(Third Edition)