PLaSK library
|
Below you have the style rules that should be obeyed when writing your code for PLaSK.
Its aim is to ensure consistent style for all solvers, which makes them easier and more natural to use by both other developers and the the end user. It is split into two parts: first the naming convention for classes, methods, functions, variables, etc. in C++ is discussed, and later there are other important considerations ensuring that the user experience is unique.
Please obey the guidelines stated in both sections, as more often than not, the naming scheme in C++ is reflected in Python interface! You are strongly advised to keep to this guidelines everywhere in your code, however in its private parts it is allowed (although really strongly discouraged) to use your own style. For public interface consider the rules stated here as more obligatory than not.
The reasoning of this style guide is consistency. But you should also know when to be inconsistent – sometimes the style guide just doesn't apply. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask!
Two good reasons to break a particular rule:
The formatting of the source is left to your taste, however the general rule of tjum is to make it legible! The more specific rules are below:
{...}
braces. The only exception is the global namespace plask
and plask::solvers::your_solver
, which contents should start from the first column.(...)
and [...]
. Also for inline comments you should put single space after double slash: // comment
.AllCapitalizedNames
for class names.mixedCase
style, with the first letter being lowercase.lower_case_with_underscores
names for very technical methods written for internal use (DataVector::remove_const
being an example). However, never do this for methods exported to the user interface!For class fields and variables it is best to use a single word: just a name or a typical physical symbol.
For short two-word terms it is best to glue them together (e.g. bbox
for bounding box) unless it obscures the legibility. If this rule is impossible to hold, you are allowed to sometimes use mixedCase
.
inTemperature
,outVoltage
.FemSolver
and not FEMSolver
.compute
. Otherwise name the methods such a way that it is clear what they do.Generally Python interface must follow the naming convention for C++. The macros prepared for creating the interface the easy way assume that the same name is used for methods and class fields in both languages (with the exception of Python properties, where you specify its name yourself). However in this case, the rules MUST be even more strictly obeyed, as this interface is visible to the end user and the consistency at this level is crucial!
lower_case_with_underscores
names. However, names of providers and receivers must match the ones from C++.2D
, 3D
, or Cyl
, which states the type of the geometry of the solver. So the correct name for e.g. a electrica solver using beta approximation of the junction in a 2D Cartesian geometry would be Beta2D
. User would see it as electrical.Beta2D
.<options>
, or better grouped under some other tags. Python properties need not to be similarly grouped (although they may)._boundary
. So for example constant temperature should be named as <temperature>
in XML and temperature_boundary
in Python.