Naming Conventions » History » Version 1
Peter Qian, 11/05/2021 04:46 PM
1 | 1 | Peter Qian | h1. OnkoDICOM Naming Convention |
---|---|---|---|
2 | |||
3 | _Authored by the OnkoDICOM 2020 Team_ |
||
4 | _Written by Matthew Archer_ |
||
5 | Draft v2 - 11/08/2020 |
||
6 | |||
7 | h2. 1. Style |
||
8 | |||
9 | The stylization of all variables, classes, functions, docstrings, comments, etc. should all be compliant with the standards defined in the "PEP 8 Style Guide":https://www.python.org/dev/peps/pep-0008/ . This extends to indentation, tabs/spaces, maximum line length, blank lines between functions, and so on. The motivation behind PEP 8 adherence falls under two main reasons: |
||
10 | # PEP has been the agreed upon “universal” style guide for the Python programming language since its publication in 2001. |
||
11 | # PyCharm, the IDE of choice for the development of OnkoDICOM, has built-in formatting hints that assists the contributors in complying to the rules that the standard has drawn out. |
||
12 | |||
13 | It is important to point out the fact that the exact style guide that is chosen is not important, only that everything within a project is _consistent_ and _readable_ throughout (which is a key point noted by PEP). It is for that reason that there are slight deviations from the PEP 8 standard that will be defined below, as internal consistency is the primary goal. |
||
14 | |||
15 | The key aspects of PEP 8 that are most relevant to OnkoDICOM’s contributors are highlighted below. The deviations are italicized. |
||
16 | |||
17 | h3. 1.1 Functions and Variables |
||
18 | |||
19 | * Function names should be lowercase, with words separated by underscores as necessary to improve readability. |
||
20 | * Variable names follow the same convention as function names, except for constants which should be written in all capital letters with underscores separating words. |
||
21 | * mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility. |
||
22 | |||
23 | h3. 1.2 Classes |
||
24 | |||
25 | * Class names should use the CapWords convention. |
||
26 | |||
27 | h3. 1.3 Packages and Modules |
||
28 | |||
29 | * Python packages should also have short, all-lowercase names, although the use of underscores is discouraged. |
||
30 | * _Module names should follow the CapWords convention._ |
||
31 | |||
32 | h3. 1.4 Mixed Case |
||
33 | |||
34 | * mixedCase should only be used when calling from/extending libraries where it is already the prevailing style, or when child classes inherit a method/class variable that are defined using this stylization. |
||
35 | * In all other instances, mixedCase is not appropriate to use. |
||
36 | |||
37 | h2. 2. Naming |
||
38 | |||
39 | All names pertaining to functions, variables, classes, etc. must all have names that are _precise_, _readable_ and _unique_. |
||
40 | |||
41 | 2.1 Choosing Names |
||
42 | |||
43 | * All names should use complete words with proper separation of words (underscores, CapsCase, etc.). |
||
44 | * Definite and indefinite articles (e.g. _the_, _a_, _an_, etc.) should be avoided. |
||
45 | * All words should be correctly spelled. If spelling of a word needs to be adjusted to avoid collision with another function or variable, then a more appropriate name should be considered. |
||
46 | * Names should be descriptive of what they do, and avoid ambiguity. |
||
47 | ** For example, OnkoDICOM’s _PatientDictContainer_ class was previous called _DICOMData_. |
||
48 | ** While DICOMData represented what the class contained and was responsible for, DICOMData is an incredibly vague name as many other classes also handled DICOM Data and the name was deemed inappropriate. |
||
49 | ** PatientDictContainer was the preferred choice of name as it describes what the class does; it is a container of dictionaries relating to patient data. |
||
50 | |||
51 | 2.2 Module Names |
||
52 | |||
53 | * When a module exists primarily to act as a containing file to define a new class (and occasionally children of that class), the module name should be identical to the name of the top-level class in the file. |
||
54 | ** For example, OnkoDICOM’s _DICOMStructure_ module defines a top-level class called _DICOMStructure_, and then further defines classes representing children of the DICOMStructure: _Patient_, _Study_, _Series_, and _Image_. |
||
55 | * In all other cases where a module acts as a container for functions or a variety of classes, the module should be named to appropriately describe what links all the contained functions and classes. All functions and classes should be able to be described by a single module name. |