Code Rant
Over the next few months I will be posting more ABAP code. One of the things that I see in many ABAP programs, including SAP code, is subroutines that are too long. A long time ago in a galaxy far away there was the great programming debate. On one side were the proponents of maximum efficiency. On the other side were these new fangled programmers called structured programmers. The maximum efficiency programmers wanted a program to be coded from top to bottom in as few statements as possible. The structured programmers would use a "main" or "driver" subroutine to drive other subroutines. By 1985 the debate was over. The structured programmers had clearly won over the spaghetti code programmers. Not only was structured code more efficient, it was also was easier to maintain. There was a great gnashing of teeth by the spaghetti programmers but the evidence was overwhelming.
I am always leery of rules but in favor of strict guidelines. In ABAP the START-OF-SELECTION or any other event should not have one hundred lines of code in it. It is highly doubtful that there is justification for any FORM to contain one hundred lines of code. If there is more than one hundred lines of code then the programmer has not thought it through and has guaranteed that the program will be unnecessarily difficult to maintain. I have been too generous - fifty lines is probably too many. The number of lines really isn't the issue. An event or a subroutine (I know we are all doing objects now and don't code subroutines) should contain one task / function. Some general guidelines - one LOOP per FORM, one SELECT per FORM, one CASE per FORM. I know that someone can come up with a good reason for exceptions but that is precisely the point. Varying from the one function per FORM / EVENT should be an exception not a general practice. I have seen an SAP FORM that contained over 700 statements. The most expensive part of programming is maintenance. Adhering to strict guidelines can help minimize those expenses.
I am always leery of rules but in favor of strict guidelines. In ABAP the START-OF-SELECTION or any other event should not have one hundred lines of code in it. It is highly doubtful that there is justification for any FORM to contain one hundred lines of code. If there is more than one hundred lines of code then the programmer has not thought it through and has guaranteed that the program will be unnecessarily difficult to maintain. I have been too generous - fifty lines is probably too many. The number of lines really isn't the issue. An event or a subroutine (I know we are all doing objects now and don't code subroutines) should contain one task / function. Some general guidelines - one LOOP per FORM, one SELECT per FORM, one CASE per FORM. I know that someone can come up with a good reason for exceptions but that is precisely the point. Varying from the one function per FORM / EVENT should be an exception not a general practice. I have seen an SAP FORM that contained over 700 statements. The most expensive part of programming is maintenance. Adhering to strict guidelines can help minimize those expenses.

0 Comments:
Post a Comment
<< Home