What I am asking here is about code readablity.
Consider the following code:
const int Apple_range_start_index=1;
const int Apple_range_length=3;
const int Orange_range_start_index=Apple_range_start_index+Apple_range_length;
const int Orange_range_length=2;
const int Cherry_range_start_index=Orange_range_start_index+Orange_range_length;
const int Cherry_range_length=5;
const int Pear_range_start_index=Cherry_range_start_index+Cherry_range_length;
const int Pear_range_length=1;
...
const int Kiwi_range_start_index=Pear_range_start_index+Pear_range_length;
const int Kiwi_range_length=7;
This code is to break an array into sub-ranges. It provides a pile of range start and range length. It is a quite extendable code and one might change each range length with no problem. The problem is that in this code I cannot change the order of ranges. If I change any two range, their value must be updated too. Using a counter can apparently solve the problem except for it cannot preserves the ranges as constant. I am looking for a neat readable solution for defining constant ranges which can be easily re-ordered.
Aucun commentaire:
Enregistrer un commentaire