Skip to content

CodingStandards

Erik Blaufuss edited this page May 31, 2023 · 4 revisions

IceCube Organization Coding Standards

We have style guidelines for both Python and C code. These are intended to keep code readable and avoid jarring transitions before code written by different people. These are summarized below. In general, the guiding principle is to make new code look like existing code. If you run into a file that obviously violates these style guidelines, please (a) hit the author with a stick and (b) do not change the style yourself. When adding to files that conform to some consistent, but different, style, prefer the style of the existing code to these guidelines unless you are replacing more than 50% of the file.

C++

The IceCube C++ coding standards should be followed when writing C++ code for IceCube.

Python

For python we will be following PEP8 (the style guide for the python standard library). PEP8 is a fairly significant document, so I will summarize the important points. Nonetheless, it is a generally good idea to read at least the section on readability. These are what we consider the most important points of PEP8:

  • Function and variables names should be lower case, with words separated by underscores, when it improves readability.
  • Class names should use CapitalizedWords.
  • Constants should be in ALL_CAPS.
  • Non-public class methods and instance variables should begin with a single underscore (this is baked into the way python implements classes).
  • Lines should be short. The standard convention is 79 characters. We're not going to be anal about this, but long lines should not be significantly longer than that, as they are hard to read. For reference, most terminals open at 80 characters wide.
  • Indentation should be done with 4 spaces. At least one person is going to continue to violate this rule, so we should generally

For example:

 CONSTANT_VALUE = 10
 
 def function_name(variable_name, other):
     do_some_things

 class MyClass:
     CONSTANCE_INSTANCE_VARIABLE = 100
     def __init__(self, input, other_input):
         self.instance_variable = input + other_input 
 
     def class_method(self, input): 
         do_things

Hat Tip: https://github.com/CMB-S4/spt3g_software/blob/master/doc/styleguide.rst

Clone this wiki locally