A colleague of mine recently asked me what would be the top 10 characteristics of program code that would makes it “best”. I spent a while before I came up with the list, which ended up to be more challenging that I thought, since it only concerned “code” and did not include other aspects of development (analysis, design, validation etc.). I thought this would be good to share, as it can help beginners and may be even others who want to analyse or review programs. I have tried to keep it short and sweet. I hope to blog more on each, in detail later.
So, without any further adieu, my top 10 (in no particular order)
Flexible and Extendable:Code needs to be built for flexibility and extensibility. For e.g., using text elements (keep literals translatable), using configurable tables (like TVARV) instead of hardcoded literals etc.
Current: Code needs to be technically current and obsolete use should be avoided including obsolete functions, obsolete statements, obsolete features (like call dialog) etc. SAP recommended methods should be used as much as possible
Standard & Named right:All programs and objects should only be named in the customer namespace, though some namespaces are not enforced by the system (e.g., Z/Z_ in functions). The names should also be differentiated for local and transportable objects. Programs, objects and code components (subroutines, methods, variables etc.) should follow the naming conventions defined by the SAP IT team and should also follow standard practices followed by SAP
Simple, Readable and Documented: Code has to readable – well named, indented and well constructed. It should be recognizable by using common business programming conventions; and documented well with comments, modification history, modification log etc. Care should be taken to remove any redundant and obsolete comments as well.
Throughput Efficient: Code has to be written and constructed for optimum throughput considering both current and future functionality, load and volume. This would include using the most suitable programming structures and loops, database read options – SQL (using right indexes, select statements), file handling (read by record / read all etc.), internal array reading (using binary search for internal tables) etc.
Reusable, Maintainable & Modular: Code has be designed with best modularity for easy maintenance as well as reusability (subroutines, classes, functions, services, etc.)
Memory Efficient:Code should be built for optimum usage of memory – like reading all records from files / tables vs reading partially, collect and process vs process each record etc.
Robust: Code should be robust to be able to handle unexpected situation and be free of unhandled errors, and retain ACID properties of any updated data – e.g, Runtime errors, exceptions handling
Verified: Code has to be checked and reviewed for common semantic errors using extended programming checks and common coding guidelines (reducing global variables, using local variables and parameters optimally, unicode compliant, dictionary and parameter compliant etc.)
Upgradable:Code should be compatible for upgrades including Unicode compatibility, avoidance of obsolete features, using SAP recommended extension and customization practices, compatible parameter handling etc.