Defining Code Quality
Learn about CISQ’s quality model and how to define code quality.
We'll cover the following...
Defining code quality
It’s tough to define the meaning of quality when it comes to program code. The reason is that all developers will have their own opinion of what it means. One developer could argue that we should focus on writing readable code because it will be easier to understand and maintain and, by that, reduce the chance of us inserting any bugs into the code. Another developer could argue that we should focus on writing compact code; that is, as few code lines as possible. Even if the code is harder to read, less code will give us fewer chances to introduce bugs in the code.
Here, the two developers would argue for the same thing—fewer bugs in the code—with two contradictory positions.
Let’s take a look at a small example using Python as our language. We want to create a list that holds all possible combinations we can get by rolling two dice.
The first one will use more code, but it will be easier to understand:
two_dice = []for d1 in range(1, 7):for d2 in range(1, 7):two_dice.append((d1, d2))print(two_dice)
On the first line, we create an empty list.
Then, we have a for
loop for the first dice. The d1
variable will get the value 1
on the first iteration, 2
on the second, and so on. Remember that the end value, 7
, is when it will stop, so this is 7
, not 6
, because it will stop when it reaches this, giving us the values 1
to 6
. We’ll then do the same kind of loop for the second dice.
On the last line, we’ll insert the values of d1
and d2
into the list. Having an extra pair of parentheses on appending the values will put them in what is called a tuple. A tuple is like a list, but it cannot be changed once we have inserted values into it. We do this to indicate that d1
and d2
belong together as one combination.
We can accomplish ...