-
Notifications
You must be signed in to change notification settings - Fork 32
Coding Style
This is non-exhaustive documentation of the coding style we use while developing Sirepo.
The style is ever evolving as we learn more about the problem we are solving and the languages we are using. If you see something that does not conform to a style described here it is likely that our style has evolved and it is time to refactor that code!
Our Python style inherits from the pykern coding style.
Do not use aliases for imports (ex. import numpy as np
). Aliases lead to confusion about where an import comes from and what the alias should be.
We no longer support py2 so if you see from __future__
you can remove them.
We support ES6 so use template strings when you see fit. In the case of multiline strings they are preferred over our older "join" syntax. Thus
const s = `
foo
bar
`;
not
const s = [
'foo',
'bar',
].join('');
We use arrow function notation when functions are assigned to a variable or used as anonymous arguments:
const f = (a, b) => {...};
fWithFunctionArg(() => {...});
If a function does nothing but return an expression, we prefer the simpler
const f = (a) => 2 * a;
except when the expression is complex or is an object literal
const f = (a, b, c) => {
return [
(-b + Math.sqrt(b**2 - 4 * a * c)) / (2 * a),
(-b - Math.sqrt(b**2 - 4 * a * c)) / (2 * a),
],
}
const g = () => {
return {x: 'X'};
}
Note that although parentheses are optional for single-argument functions, we use them to ensure consistency and to simplify searches for functions; const f = (a) => 2 * a;
, not const f = a => 2 * a;
License: http://www.apache.org/licenses/LICENSE-2.0.html
Copyright ©️ 2015–2020 RadiaSoft LLC. All Rights Reserved.
- Activait
- Controls
- elegant
- FLASH
- Genesis
- JSPEC
- JupyterHub
- MAD-X
- OPAL
- Radia
- Shadow
- Synchrotron Radiation Workshop (SRW)
- Warp PBA
- Warp VND
- Zgoubi
- Authentication and Account Creation
- How Your Sirepo Workspace Works
- Navigating the Sirepo Simulations Interface
- How to upload a lattice file
- How to share a Sirepo simulation via URL
- How Example simulations work
- How to report a bug in Sirepo
- Using lattice files in Sirepo
- Resetting an Example Simulation to default
- Backup SRW Sirepo simulations
- SRW Aperture
- SRW Brilliance Report
- SRW Circular Cylinder Mirror
- SRW CRL
- SRW Crystal
- SRW Electron Beam
- SRW Elliptical Cylinder Mirror
- SRW Fiber
- SRW Flux
- SRW Fully Coherent Gaussian Beam
- SRW Import Python or JSON Simulation File
- SRW Initial Wavefront Simulation Grid
- SRW Intensity Report
- SRW Planar Mirror
- SRW Power Density Report
- SRW Propagation Parameters
- SRW Single Electron Spectrum Report
- SRW Spherical Mirror
- SRW Toroid Mirror
- SRW Watchpoint
- SRW Additional Documentation