From Project ROSALIND: Inferring mRNA from Protein http://rosalind.info/problems/mrna/ Version History 2020-04-13 — David M. Ng — Initial version.
When we are counting in a program, we usually initialize the counter variable to 0 (e.g., seqPos). When we are accumulating (summing) in a program, we initialize the accumulator variable to 0. But when we are finding the product of a series of factors, we initialize the product variable to 1 because 1 is the multiplicative identity. (Recall that 0 is the additive identity.) There are three stop codons in the conventional genetic code. A variable numStopCodons is initialized to 3, and then the variable is used instead of the constant 3. This makes the code more readable, with a descriptive name rather than a “magic” number. (A rule of thumb is, the only constants that should appear in code is 0 or 1, not counting initialization of variables. Some programming languages allow variables to declared as constants so the value can only be used after initialization, but not changed.) The modulo factor is used three times in the code. A variable moduloFactor is used for this value. In addition to the readability rationale, it also improves maintainability in that if we decide to change the value of the modulo factor, it need be changed in only one place in the code. Remember to delete the contents of lists as necessary as part of initialization. Otherwise, the list may inadvertently get longer than expected.