Maintaining proper coding style is very important for any large software project, such as MISP. Here’s why:
ClassName,someVariable, someFunction, someArgumentif or before { in PHP, Python, JavaScript, and similar in other languages. Whether and where to also use spaces within expressions, such as (y*4+8) vs. (y * 4 + 8) is left to the developer’s judgment. Do not put spaces immediately after or before the brackets in expressions, so avoid constructs like this: if ( condition ) and use ones like this: if (condition) instead.class HttpClientJsonException extends Exception
{
/** @var HttpSocketResponse */
private $response;
}
AttachmentTool.phpload_warninglists.pybootstrap-colorpicker.jsAlways prefer readability over trickiness! No need to use tricks to save a few lines of code.
Make sure your code compiles and builds without warnings
Always think first about interfaces (e.g. function arguments, or class methods) and data structures before you start writing the actual code.
Use comments to explain non-trivial code fragments, or expected behavior of more complex functions, if it is not clear from their name.
Do not use comments for code fragments where it is immediately clear what the code does. E.g. avoid constructs like this:
function ret(tp, style, cont) {
type = tp; content = cont;
// Return style
return style;
}
In production code, there should be little to no commented or disabled code fragments. Do not use comments to disable code fragments, unless you need to. But generally, there is little excuse to keep old, unused code fragments in the code. Instead, use the functionality provided by the source code management system, such as git. For example, create a special branch for storing the old, unused code – this way you will always be able to merge this code into upstream in the future.
Try not to hardcode values in the code.
Please attempt to follow our commit messages best practices when writing your git commit messages. Also, when committing changes that will resolve an issue once merged, include #NNNN in the commit message, NNNN being the issue number. Then, GitHub will automatically reference this commit on the corresponding issue, once the branch is pushed to our Git repository. For example:
chg: [doc] Fix spelling errors (#3120)