An Empirical Survey on Usefullness of Comments in Software Programming
Total Page:16
File Type:pdf, Size:1020Kb
International Journal of Computing and Corporate Research ISSN (Online) : 2249-054X Volume 3 Issue 4 July 2013 Manuscript ID : 2249054XV3I4072013-04 AN EMPIRICAL SURVEY ON USEFULNESS OF COMMENTS IN SOFTWARE PROGRAMMING LANGUAGES Manjot Singh Ahuja, Surender Dhaiya, Neha Sadana {manjot.ahuja, surendahiya, sadananeha25}@gmail.com Computer Science and Engineering Department Shivalik Institute of Engineering and Technology, Aliyaspur (Ambala) ABSTRACT Each programming language and script has comments to make it further reusable. This its own coding conventions. There are documentation will take form of external, numerous general points that can be internal documentation, comments, and followed to ensure that the code is well readme files. organised so that it can be easily understood for maintenance and External documentation - Explains the reengineering. These guidelines are helpful methods of software development. in formalising code so that interpretation, reuse, maintenance, re-engineering and Internal documentation - Explains the way reverse-engineering of code become to implement the code. easier. The source code comment gives high-level advice for software developer. Comments - Comments must be added to This paper presents an overview of the code to explain the implementation conventions and importance of comments details of the source code. It is mandatory in source code during development as well to avoid adding of obvious or lengthy as in maintenance. information. Prior to the project development, we should agree on how Keywords - Code Quality, Source Code, frequent comments should be and their Source Code Comments, Source Code location, format and length in the file. Comments Quality These conventions may need to be agreed on for block, single-line and end-of-line comments. 1 Introduction Readme file - Every package should have Source code documentation is the text the readme file unfolding the purpose and which accompanies computer software and functionality of the software and either explains how it operates or how to information on exterior dependencies. use it. Code comments are used to embed programmer-readable remarks in the source code of a program. These 2 Taxonomy of the Comments annotations are ignorable to compilers and 2.1 Prefacing interpreters. The source code comments are typically additional artifacts with the This is the practice of starting each rationale of the ease to comprehension of programming with a block comment that source code. The syntax and rules for briefly describes it. Ideally, the preface comments diverge and are typically should not be overly long, and it should defined in a programming language summarize the purpose of its programming specification. While developing software it unit. The advantages of prefacing are is important that you include the clear twofold, it is a useful tool for any documentation as well as the code maintainers who may need to understand International Journal of Computing and Corporate Research ISSN (Online) : 2249-054X Volume 3 Issue 4 July 2013 Manuscript ID : 2249054XV3I4072013-04 the code in the future; but it can also be Python, Ruby, Windows PowerShell, PHP, beneficial for the developer writing the Maple), % (TeX, Prolog, MATLAB, code, helping to concretize the purposes in Erlang, S-Lang, Visual Prolog), etc.. his mind. In addition, best practices have always stipulated that programming units Block comments - Block comments are should be single-purpose, and in writing generally those that use a delimiter to the prefacing comments, the developer indicate the beginning of a comment, and will catch himself if he is about to flout another delimiter to indicate the end of a this rule. comment. In this context, whitespace and newline characters are not counted as 2.2 Comment-Driven Development delimiters. This is a programming methodology that Examples: /* */ (C, C++, C#, D, Go, Java, encourages the developers to start out JavaScript, Objective-C, PHP, Visual complex projects by building a wireframe Prolog, CSS), { } (Object Pascal (Delphi), of their procedures using little more than Pascal), etc. comments and basic pseudo code to describe each step of the algorithm. CDD 4 Approaches and Protocols for help developers to encounter and work out Comments problems before they write a line of actual code; it also has the advantage of helping Commenting styles should be governed by clearly delineate the routes between the a company’s development guidelines and, high-level problem and the many small- even within these guidelines, there is often picture fractals it is composed of. The enough wriggle room for individual style comments created using CDD may survive and subjectivity. The following are few the process of actual coding and rules and practices that should be followed development as line comments throughout when commenting code. the programming unit; however, it sometimes make sense to delete them after To include a preface: It need not be a long their purpose has been served. essay, in fact, it should not be long. However, it is important to include one. 3 Comments Style and Format Apart from focusing the developer’s mind around the task and assisting any • Style (inline/block) maintainer that may come along in the • Parse rules (ignored/interpolated/stored future, prefaces can serve an important, in memory) additional function. Some languages, most • Recursivety (nestable/non-nestable) notably Java, but also PHP include API- • Uses (docstrings/throwaway generating functionality: Javadoc and comments/other) PHPdoc, respectively. PL/SQL presents us with no such nicety, but if all Inline Comments - Inline comments are programming units contain prefacing generally those that use a newline comment blocks, then we can write of our character to indicate the end of a comment, own quite easily. and an arbitrary delimiter or sequence of tokens to indicate the beginning of a Include a revision history : Anyone comment. maintaining your code in the future will thank you for including a revision history. Examples: // (C++, C#, D, Go, Java, The identity of the developer who has JavaScript, Object Pascal (Delphi), made a particular change is not so Objective-C, PHP), # (bash, Cobra, Perl, important, however, it may one day be International Journal of Computing and Corporate Research ISSN (Online) : 2249-054X Volume 3 Issue 4 July 2013 Manuscript ID : 2249054XV3I4072013-04 vital to know when a change was made would make the code very readable and why. and will not need many comments. • Do not write comments if the code is Use line comments: A good rule is to use a easily understandable without single line comment at the start of each comment. The drawback of having lot logical block describing what it does. If, in of comments is, if you change the code the future, someone needs to maintain your and forget to change the comment, it code, they should not need to read every will lead to more confusion. line of code to pinpoint the section they • Fewer lines of comments will make the intend to edit; in fact, they should be able code more elegant. But if the code is to navigate your whole procedure or not clean/readable and there are less package without reading a single line of comments, that is worse. code outside the actual section they are • If you have to use some complex or looking for. A good developer, unlike a weird logic for any reason, document it good novelist, is one whose best work is very well with sufficient comments. never read in full. • If you initialize a numeric variable to a special number other than 0, -1 etc, Never depend on your memory: Writing document the reason for choosing that something complicated? Comment it. value. Code, algorithms and assumptions that are perfectly clear at the time of writing, can 5 Literature Survey quickly fester in a morass of spaghetti code with time. In early 1980s Donald Knuth suggested literate programming [5], in order to Comment while maintaining code: If you combine the process of software are forced to wade through old poorly- documentation with software commented or uncommented code that you programming. Comments are ignored by or another developer has written, do not compiler, so, in order to differentiate leave it as you found it. Comment it. source code and documentation, a specific While you may not be responsible for the documentation or programming syntax has way you find code, you are responsible for to be used. Programmers typically lack the the way you leave it. appropriate tools and processes to create and maintain documentation, it has been Keep it simple: Comments should be widely considered as an unfavorable and easily readable. Keep them as short as labor-intensive task within software possible, and as plain as possible. Unless projects [6]. absolutely necessary, do not include any For generating comments in JAVA, code in your comments. Javadoc [7] is an automated tool that generates API documentation in HTML Good and meaningful comments make using Java source code and source code code more maintainable. However, comments. Javadoc comments added to • Do not write comments for every line source code are distinguishable from of code and every variable declared. normal comments by a special comment • Use // or /// for comments. Avoid using syntax (/**). /* … */ In [8], Khamis et al. provided an analysis tool called JavadocMiner for analyzing the • Write comments wherever required. quality of inline documentation. Thereby, But good readable code will require the authors mainly focused on inline- very less comments. If all variables documentation in the form of Javadoc and method names are meaningful, that comments. By using a set of heuristics, International Journal of Computing and Corporate Research ISSN (Online) : 2249-054X Volume 3 Issue 4 July 2013 Manuscript ID : 2249054XV3I4072013-04 they aimed to evaluate both the quality of In addition to [10], Ying et al [11] also the language and the consistency between investigated the role of task comments. source code and its comments.