Design Philosophy and Style Guide#
Design Philosophy#
Do Not Repeat Yourself (DRY)
If it’s worth doing, it’s worth doing well.
Use abstraction and inheritance smartly.
Use
@propertygetters, and if needed setters. Setters must verify and clean user inputs. For the most part usemake_prop_val_node(), andmake_prop_pointer().Fail early and politely. If there’s something that might be bad: the user should get a helpful error as soon as the error is apparent.
Test. test. test. The goal is to achieve 100% test coverage. Unit test first, then do integration testing. A new feature merge request will ideally have around a dozen new test cases.
Do it right the first time.
Document all functions.
Expect everything to mutate at any time.
Avoid relative imports when possible. Use top level ones instead: e.g.,
import montepy.cell.Cell.Defer to vanilla python, and only use the standard library. Currently the only dependencies are numpy and sly. There must be good justification for breaking from this convention and complicating things for the user.
Style Guide#
Spaces not tabs with 4 spaces for an indent.
External imports before internal imports with a blank line in between. All imports are alphabetized.
Naming Conventions#
Follow PEP 8 naming conventions e.g.,
lower_case_with_underscoresfor variables, methods, functions, and module names, etc.CapitalizedWordsfor class namesMCNP_ClassNameis an exception. For all Other acronyms use:AcronymMoreWords. Above all, prioritize legibility.
UPER_CASE_WITH_UNDERSCORESfor pseudo-constant variables_single_leading_underscoreshould be used for almost all internal attributes.__double_leading_underscoreshould be used for private internal attributes that should not be accessed by users or sub-classes.
Variables should be nouns/noun-phrases
Functions/methods should be verb/verb-phrases.
Properties/attributes of classes should be nouns or
is_adjectivephrases.Collections should be a plural noun, and single instances should be singular. In loops there should be consistent names, e.g.,
for cell in cells:.When appropriate names should mirror Python core libraries (e.g.,
NumberedObjectCollectiontries to mirror methods ofdict,list, andset).Within reason: avoid abbreviating words. Above all, prioritize legibility.
For user facing functions and attributes, short names are best. (
surface_constants, really should have beenconstantsin hind-sight).