in reply to Maintainable code is the best code Part II

A note. Often some of the biggest maintainability questions can be solved by asking a question you hadn't thought of. For instance you are asking about the best code for converting between a type number and a corresponding name in Perl. I look at that and immediately ask, "Why are you using a numerical code in Perl?"

My answer to that question would be, "Unless forced by external circumstances, I wouldn't." Numerical codes are inherently less maintainable to program with than string descriptions. For a type code, perhaps string descriptions which go through a function that catches any typos.

And, of course, if I don't have numerical codes floating around, I no longer need to think about the most maintainable way to write the conversion code...

  • Comment on Re (tilly) 1: Maintainable code is the best code Part II

Replies are listed 'Best First'.
Re: Re (tilly) 1: Maintainable code is the best code Part II
by dragonchild (Archbishop) on Oct 04, 2001 at 18:43 UTC
    And, frankly, I wouldn't use numerical codes to describe stuff. However, say I'm given a set of things in an array and I need to name them according to their position in the array, plus some fixed string. This type of conversion between number and name is very useful. And, this is something I and my coworkers are doing a lot in our current project.

    These two meditations were prompted by my helping a coworker of mine learn good programming practices, both in general and in Perl. So, I used the examples I used with her, hoping to get at some generic ideas.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.