Single indirection vs double indirection3/28/2023 ![]() My suggestion at the time was that one level of indirection would likely make this documentation baffling for new staff, and two levels would give the author no hope of maintaining the referential integrity of his own edifice. My brief was to suggest ways of improvement. The documentation was actually riddled with circular references, or references left dangling due to the target document being updated without regard to it being a call target. Not only unmanageable for the intended audience - trainees and similar - but even for the author. Unfortunately the number of levels of indirection - usually between half a dozen and a dozen - was unmanageable from a human factors point of view. This was not web-based with hyperlinks, it was paper-based - and as a series of separate documents, not as a bound book with a table of contents. This was done intentionally, to avoid writing redundant information into each document, and the possibility of update anomalies. What this meant was that there was extensive use of indirection and cross-references in the documentation, used like procedure calls would be in a programming language. I once worked for a company that had attempted to analyse and document its business processes, and the way the approach was described to me by the author was that he had written the process documents like computer code, but in English. I was mildly perturbed when the problem I was chasing just vanished swiftly and silently away.)ĪND part of it is because code that is only doing one level of indirection is usually a LOT easier for the poor maintenance schlub to understand. I did the rewrite because the original code was an unreadable pile of spaghetti and pointers to pointers to pointers. (I did not do the rewrite because I suspected a thrashed cache. No, the vendor is NOT going to fix them any time soon, and in any case those chips are already out in the field.) I personally fixed a problem, that smelled like one of those, on a processor for which the manufacturer had already warned about issues like this, by rewriting the code to be very careful about locality of references. I have seen processors that can deliver up erroneous results if you thrash the cache in certain ways. ![]() Part of this is because modern processors have complicated data cache, and even more complicated memory allocation schemes, and walking multiple levels of indirection (through long pointer chains) can thrash the holy crap out of the cache. Part of this is because prudence dictates that you check every pointer for NULL before you dereference it, and that's hard to do if you write more than one level of indirection. It is EXTREMELY rare that it is actually a good idea to write code with more than one level of indirection at any given instant. ![]() (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.) It simply means that it might potentially be an indication that there could possibly be an inherent inefficiency in the architecture of your code. 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.īut does that mean you should never allow more than 3 levels of indirection? Absolutely not. 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. 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. There are no guidelines or any practical limits on indirection.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |