In a C++ program that doesn\'t contain legacy C code, is there a guideline regar
ID: 654242 • Letter: I
Question
In a C++ program that doesn't contain legacy C code, is there a guideline regarding the maximum number of levels of indirection that should be used in the source code? I know that in C (as opposed to C++), some programmers have used pointers to pointers for a multiple dimension array, but for the case of arrays, there are data structures in C++ that can be used to avoid the pointers to pointers.
Are users who still create pointers to pointers (or more than this) trying to use pointers to pointers only for performance ETC. reasons?
I have tried NOT to use any more than a pointer to a pointer, only in the case that a pointer needed modification; does anyone have any other official or unofficial guidelines or rules regarding the number of levels of indirection?
Explanation / Answer
There are no guidelines or any practical limits on indirection. There's no good reason to place a constraint like this unless you're regularly dealing with several levels of indirection in a case indicative of a sloppy design.
That is to say that there are valid cases where 4, 5, 6, or more levels of indirection is to be expected, but these are rare and should not typically appear in your code unless someone has done something terrible, not directly related to the level of indirection being employed.
If you are finding yourself using, say, 3 or more levels of indirection, then you should probably consider whether your architecture needs to be changed.
But does that mean you should never allow more than 3 levels of indirection? Absolutely not. It simply means that it might potentially be an indication that there could possibly be an inherent inefficiency in the architecture of your code. Nothing more. (Do note the deliberate vagueness of that statement: it is a mere possibility of something that could lead to a problem, not necessarily an actual problem.)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.