How does the Lenght of a Method affect Maintainability
Determining how the length of a method affects maintainability will depend on the type of methods available, and how their lengths each affect maintainability. As the Perl Slogan says, “There’s More Than One Way to Do It”. This slogan also applies to a shell script, and it simply indicates that although there are different methods used for maintainability but that some methods of executing a given task are less tasking than others, as seen in the long and short method theory.
Deciding on how terse a chunk of code should be depends on the individual(s) involved, although it is better to keep in mind that in terms of ease, readability, management and modification, that, it is best to be less terse, “use a short method” unless there is a compelling reason to do otherwise. However, if there becomes a compelling reason to use a long method, use it by mitigating the negative effects on readability with a strong, clear and concise comments. In totality, it is best to use a less terse style (short methods) for maintainability.
The length of a method used has a lot to do with its outcome on maintainability due to the length of time it will take to restore the system to its functional status following its removal from operations for an upgrade. Using a less lengthy method, “sort method” for improving system maintainability, can increase availability, performance, reliability and reduce the effects of run time problems. While using a long method may only make the maintenance task harder.
Statement of problem
Maintainability is the process by which a system undergoes changes with a certain degree of ease. The changes achieved could affect features, services, components, interfaces and more when fixing errors, changing functionality and attaining new business requirements. The maintainability needed for an application is often times a function of its total quality attributes. However, there are some key issues that make the length of method affect maintainability and some of them are;
. For JIT to be able to optimize, the requirement is to write shorter methods and not lengthy methods.
. Overhead for making method calls most often than not is inconsequentially small in most cases.
The use of long method in many levels is wrong. Shorter methods produce better long lasting results than long methods, and in addition, methods are supposed to do one thing, one thing only while delegating sub- items to other routines but long methods do more than one thing which makes it more complex.
Shorter methods produce better results, it creates for a better performance benefit by making codes that are less prone to bugs and errors because of its simplicity rather than trying to outsmart the run-time or compiler with long methods. It is of utmost importance that a code is simple, readable, easy to use, modular, maintainable and modifiable. Short methods generally lead to readability.
Figure 2: Assessment of maintainability
Short methods work best for readability, understandability, maintainability and more (less than 15 lines)
Long method are not as good as short methods (16 lines and above)
Some Introductory Remarks:
Methods for maintainability, provide a mechanism that is used for manipulating and accessing data coded in an object. A method generally is a subroutine that is linked with an object and it usually consists of a chain of programming statement designed to perform an action.
The best single requirement that helps explain how the length of a method affects maintainability is by keeping them properly testable. Unit- test every method you know and the result may come out looking good, but if you skimp on testing then the result may be mediocre. When a method proves difficult to test thoroughly, then that means that the method is likely to be too long, and the bad thing about methods that are too long is that it tries to do too many things and therefore becomes even harder to read, maintain and becomes a haven for bugs. Long methods are somewhat better, but when they are too long, it becomes a problem.
Long Methods: An Overview
Judging from an extensive book written by EwDijkstra; titled “A Discipline of Programming”, it is okay to say that long functions are good but when they become too long then they become bad. Some studies even claim that long methods, improve readability and give a vivid understanding of what a code does and allows you to prove it. However, Irrespective of this fact, along method is still hard to maintain, especially within a commercial time frame where it is most times impossible to find the original writer or when the program itself is old. While short methods are easy to maintain and extend, long methods are not only hard to maintain but are also hard to extend. Therefore, it is best to always strive to write shorter clearer functions when possible. A long method is characterized by its over 16 lines, while some extremely long methods have up to 50- 100 lines of code long. IMHO, from Long methods are never justified in handwritten code. Code done using long methods can be greatly simplified and made clearer with a little re-factoring. Long methods are bad; they smell because they conceive the algorithm within the implementation in some cases, mixing two separate levels of abstraction.
Short Methods: An Overview
it is a logistic fact that shorter methods are easier to maintain than longer methods, and shorter methods have less than 15 lines of code. Shorter methods are more reliable and precise, they do what they say they do because you wrote them that way, but the same does not tell of a longer method. When the source code of a system is easy to comprehend, than the maintainability is better, leading to reduced costs and giving room for good development resources to be used elsewhere. Short methods allow a person to separate the algorithm (logic) from the implementation of the logic which is known as abstraction, and that is what programming is about.
Short methods enhance reuse, readability, understandability and maintainability. The best part is that a person can continuously keep the method short of ensuring that each method does a single function.
A method as earlier stated, is a chunk of code needed in multiple places, and for long chunk of code, you may need to split it up, but for utmost result, a person needs to balance readability, performance and complexity. With short methods, a person can code for readability, confirm correctness, and then move to optimize for performance.
The following hypotheses are generated from the reviewed literature:
HO 1: long methods for maintainability have codes longer than 16 lines while short methods in maintainability code with less than 15 lines.
HO 2: longer methods are bad, lacks abstraction, are poorly named and cryptic variable names, whereas small method allow for readability, understandability, maintainability, and creates better results.
HO 3: when a situation is compelling, a long method is okay to use, but when the method used is extremely lengthy, ranging from 100 to 150 lines then that project is going to be bad. A long method may be manageable, especially when it is necessary, but when it becomes too lengthy, then it is terribly bad.
HO 4: short methods give a good balance and does one thing only whereas, long methods tend to do more than one thing which then makes the whole process complicating to read or understand
Short Methods are best for MaintainabilitySee results without voting
More by this Author
Presenting your lover with an engagement ring should be a big deal. Therefore presenting the engagement ring in style is preferred. Below are the unique five ways to give an engagement ring.
No comments yet.