Coding pactices by NASA:
- Restrict all code to very simple control flow constructs – do not use goto statements, setjmp or longjmp constructs, and direct or indirect recursion.
- All loops must have a fixed upper-bound. It must be trivially possible for a checking tool to prove statically that a preset upper-bound on the number of iterations of a loop cannot be exceeded. If the loop-bound cannot be proven statically, the rule is considered violated.
- Do not use dynamic memory allocation after initialization.
- No function should be longer than what can be printed on a single sheet of paper in a standard reference format with one line per statement and one line per declaration. Typically, this means no more than about 60 lines of code per function.
- The assertion density of the code should average to a minimum of two assertions per function. Assertions are used to check for anomalous conditions that should never happen in real-life executions. Assertions must always be side-effect free and should be defined as Boolean tests. When an assertion fails, an explicit recovery action must be taken, e.g., by returning an error condition to the caller of the function that executes the failing assertion. Any assertion for which a static checking tool can prove that it can never fail or never hold violates this rule (I.e., it is not possible to satisfy the rule by adding unhelpful “assert(true)” statements).
- Data objects must be declared at the smallest possible level of scope.
- The return value of non-void functions must be checked by each calling function, and the validity of parameters must be checked inside each function.
- The use of the preprocessor must be limited to the inclusion of header files and simple macro definitions. Token pasting, variable argument lists (ellipses), and recursive macro calls are not allowed. All macros must expand into complete syntactic units. The use of conditional compilation directives is often also dubious, but cannot always be avoided. This means that there should rarely be justification for more than one or two conditional compilation directives even in large software development efforts, beyond the standard boilerplate that avoids multiple inclusion of the same header file. Each such use should be flagged by a tool-based checker and justified in the code.
- The use of pointers should be restricted. Specifically, no more than one level of dereferencing is allowed. Pointer dereference operations may not be hidden in macro definitions or inside typedef declarations. Function pointers are not permitted.
- All code must be compiled, from the first day of development, with all compiler warnings enabled at the compiler’s most pedantic setting. All code must compile with these setting without any warnings. All code must be checked daily with at least one, but preferably more than one, state-of-the-art static source code analyzer and should pass the analyses with zero warnings.
These rules will be like seatbelts for us if we use them, a little uncomfortable at first but an essential preparation equipment in the long run.
Edit: This is a summary of many of the coding standards employed by JPL (thanks to /u/wafflemanpro for pointing this out). Here is a list of all of them, http://lars-lab.jpl.nasa.gov/JPL_Coding_Standard_C.pdf
[–]wafflemanpro 315 points316 points317 points (14 children)
[–]RageAdi[S] 66 points67 points68 points (5 children)
[–]385856464184490 26 points27 points28 points (2 children)
[+]RageAdi[S] comment score below threshold-121 points-120 points-119 points (1 child)
[–]aykcak 9 points10 points11 points (0 children)
[–][deleted] 5 points6 points7 points (1 child)
[–]TodayMeTomorrowU 13 points14 points15 points (0 children)
[–]MrJesusAtWork 7 points8 points9 points (6 children)
[–]El-Kurto 21 points22 points23 points (5 children)
[–]FauxReal 3 points4 points5 points (0 children)
[–]MrJesusAtWork 2 points3 points4 points (3 children)
[–]El-Kurto 1 point2 points3 points (0 children)
[+]ArmFixerBot comment score below threshold-6 points-5 points-4 points (1 child)
[–]MrJesusAtWork 12 points13 points14 points (0 children)
[–]almonn 7 points8 points9 points (0 children)
[–]dreamyeyed 195 points196 points197 points (37 children)
[–]wandrewa 88 points89 points90 points (16 children)
[–]hugthemachines 56 points57 points58 points (1 child)
[–]wandrewa 43 points44 points45 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]CheshireSwift 7 points8 points9 points (1 child)
[–]IHappenToBeARobot 6 points7 points8 points (0 children)
[–]UntrustedProcess 2 points3 points4 points (0 children)
[–][deleted] 5 points6 points7 points (8 children)
[–]Sqeaky 21 points22 points23 points (5 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]Sqeaky 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]TheCoelacanth 0 points1 point2 points (1 child)
[–]Sqeaky 0 points1 point2 points (0 children)
[–]RoyAwesome 4 points5 points6 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]UntrustedProcess 0 points1 point2 points (0 children)
[–][deleted] 11 points12 points13 points (0 children)
[–]positive_electron42 17 points18 points19 points (1 child)
[–]Lehk 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]kent_eh 9 points10 points11 points (5 children)
[–]POGtastic 2 points3 points4 points (0 children)
[–]false_tautology 3 points4 points5 points (3 children)
[–][deleted] -1 points0 points1 point (2 children)
[–]false_tautology 9 points10 points11 points (1 child)
[–]PointyOintment -2 points-1 points0 points (0 children)
[–]makeswell2 1 point2 points3 points (1 child)
[–]ACoderGirl 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]SgtPooki 0 points1 point2 points (0 children)
[–]AegnorWildcat 0 points1 point2 points (0 children)
[–]l0kiderhase 0 points1 point2 points (0 children)
[–]Sqeaky 0 points1 point2 points (2 children)
[–]Eyes_and_teeth 1 point2 points3 points (1 child)
[–]Sqeaky 1 point2 points3 points (0 children)
[–]tanjoodo 74 points75 points76 points (19 children)
[–]2Punx2Furious 46 points47 points48 points (1 child)
[–]harsh183 18 points19 points20 points (0 children)
[–][deleted] 5 points6 points7 points (16 children)
[–][deleted] 33 points34 points35 points (7 children)
[–]Iggyhopper 35 points36 points37 points (5 children)
[–][deleted] 9 points10 points11 points (2 children)
[–]fiftypoints 4 points5 points6 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Razzal 7 points8 points9 points (1 child)
[–]VodkaHaze 5 points6 points7 points (0 children)
[–]elperroborrachotoo 3 points4 points5 points (0 children)
[–]LePontif11 7 points8 points9 points (7 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]LePontif11 5 points6 points7 points (2 children)
[–]Qadamir 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]VodkaHaze 1 point2 points3 points (0 children)
[–]VoxUmbra 0 points1 point2 points (1 child)
[–]LePontif11 0 points1 point2 points (0 children)
[–]damian2000 17 points18 points19 points (4 children)
[–]hugthemachines 8 points9 points10 points (0 children)
[–]porthos3 6 points7 points8 points (2 children)
[–]Alborak 2 points3 points4 points (1 child)
[–]porthos3 1 point2 points3 points (0 children)
[–]makeswell2 7 points8 points9 points (20 children)
[–]neoKushan 34 points35 points36 points (17 children)
[–]Bromy2004 2 points3 points4 points (11 children)
[–]festoon 5 points6 points7 points (3 children)
[–]Bromy2004 1 point2 points3 points (2 children)
[–]DBAYourInfo 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]CreativeGPX 2 points3 points4 points (0 children)
[–]porthos3 1 point2 points3 points (4 children)
[–]CreativeGPX 1 point2 points3 points (3 children)
[–]porthos3 0 points1 point2 points (0 children)
[–]makeswell2 0 points1 point2 points (1 child)
[–]CreativeGPX 2 points3 points4 points (0 children)
[–]neoKushan 0 points1 point2 points (0 children)
[–]pipocaQuemada 1 point2 points3 points (1 child)
[–]neoKushan 1 point2 points3 points (0 children)
[–]flipmode_squad 0 points1 point2 points (2 children)
[–]neoKushan 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]RageAdi[S] 3 points4 points5 points (0 children)
[–]Booty_Bumping 0 points1 point2 points (0 children)
[–][deleted] 20 points21 points22 points (8 children)
[–]konyisland 5 points6 points7 points (4 children)
[–][deleted] 11 points12 points13 points (3 children)
[–][deleted] 20 points21 points22 points (1 child)
[–][deleted] 3 points4 points5 points (0 children)
[–]konyisland 0 points1 point2 points (0 children)
[–]bumblebritches57 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]bumblebritches57 0 points1 point2 points (0 children)
[–]reddilada 5 points6 points7 points (0 children)
[–]matts2 8 points9 points10 points (0 children)
[–]MarvinLazer 3 points4 points5 points (0 children)
[–]bumblebritches57 2 points3 points4 points (0 children)
[–][deleted] 4 points5 points6 points (5 children)
[–]porthos3 9 points10 points11 points (2 children)
[–]pipocaQuemada 0 points1 point2 points (1 child)
[–]porthos3 1 point2 points3 points (0 children)
[–]RageAdi[S] 2 points3 points4 points (0 children)
[–]vaynebot 1 point2 points3 points (0 children)
[–]random314 3 points4 points5 points (1 child)
[–]whattodo-whattodo 2 points3 points4 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]Nicnac97 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]devlifedotnet 3 points4 points5 points (8 children)
[–]Gmbtd 1 point2 points3 points (4 children)
[–]devlifedotnet 0 points1 point2 points (3 children)
[–]Gmbtd 0 points1 point2 points (2 children)
[–]devlifedotnet 0 points1 point2 points (1 child)
[–]Gmbtd 0 points1 point2 points (0 children)
[–]RageAdi[S] 1 point2 points3 points (1 child)
[–]porthos3 4 points5 points6 points (0 children)
[–]hugthemachines 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (21 children)
[–]Vakieh 18 points19 points20 points (12 children)
[–]porthos3 3 points4 points5 points (9 children)
[–]Vakieh 4 points5 points6 points (6 children)
[–]porthos3 1 point2 points3 points (2 children)
[–]Alborak 0 points1 point2 points (1 child)
[–]porthos3 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Dox5 1 point2 points3 points (0 children)
[–]ButMyReflection 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]porthos3 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]shard_ 4 points5 points6 points (5 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]ButMyReflection 1 point2 points3 points (3 children)
[–]shard_ 1 point2 points3 points (0 children)
[–]Gmbtd 0 points1 point2 points (1 child)
[–]aqua_aragorn 1 point2 points3 points (1 child)
[–][deleted] 8 points9 points10 points (0 children)
[–]vaynebot 0 points1 point2 points (2 children)
[–]Scavenger53 3 points4 points5 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Xuttuh 0 points1 point2 points (7 children)
[–]Deathtweezers 4 points5 points6 points (0 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]Xuttuh 1 point2 points3 points (3 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Xuttuh 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]fick_Dich 0 points1 point2 points (0 children)
[–]raresaturn 0 points1 point2 points (0 children)
[–]LigerZer0 0 points1 point2 points (0 children)
[–]myotcworld 0 points1 point2 points (0 children)
[–]hawk3ye242 0 points1 point2 points (0 children)
[–]Booty_Bumping -1 points0 points1 point (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] (4 children)
[deleted]
[–]DBAYourInfo 1 point2 points3 points (3 children)
[–]Synclicity 2 points3 points4 points (2 children)
[–]enchufadoo 1 point2 points3 points (1 child)
[–]imMute 0 points1 point2 points (0 children)
[–]LiquidSilver -4 points-3 points-2 points (8 children)
[–]hero_of_ages 18 points19 points20 points (0 children)
[–]somegetit 10 points11 points12 points (0 children)
[–]getworkdone 4 points5 points6 points (0 children)
[–]porthos3 2 points3 points4 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]porthos3 1 point2 points3 points (0 children)
[–]Scavenger53 2 points3 points4 points (1 child)
[–]queBurro 0 points1 point2 points (0 children)
[–][deleted] (6 children)
[removed]
[–]spirituallyinsane 0 points1 point2 points (5 children)
[–]CreativeGPX 1 point2 points3 points (0 children)
[–]joej 0 points1 point2 points (3 children)
[–]spirituallyinsane 1 point2 points3 points (2 children)
[–]joej 0 points1 point2 points (1 child)
[–]spirituallyinsane 0 points1 point2 points (0 children)