Automatic Segmentation of Method Code into Meaningful Blocks: Design and Evaluation

Author : Wang, Xiaoran; Pollock, Lori; Vijay-Shanker, K.
Date : Feb 2013
Publisher : John Wiley and Sons Ltd.
Journal : Journal of Software Maintenance and Evolution: Research and Practice
Volume : 10
Pages : 2047-7481
Keyword(s) : Program understanding, readability,software tool,automatic formatting
Document Type : Article

Abstract :

Good programming practice and guidelines suggest that programmers use both vertical and horizontal spacing to visibly delineate between code segments that represent different algorithmic steps or high level actions. Unfortunately, programmers do not always follow these guidelines. Editors and IDEs can easily indent code based on syntax, but they do not currently support automatic blank line insertion, which presents more significant challenges involving the semantics. This paper presents and evaluates a heuristic solution to the automatic blank line insertion problem, by leveraging both program structure and naming information to identify meaningful block, consecutive statements that logically implement a high level action. Our tool, SEGMENT, takes as input a Java method, and outputs a segmented version that separates meaningful blocks by vertical spacing. We report on several studies involving human judgments to evaluate the effectiveness of the automatic blank line insertion algorithm, for different size methods and for different levels of programmer expertise. The results indicate strong positive overall opinion of SEGMENT’s effectiveness in comparison with both developer-written blank lines and blank lines inserted by newcomers to the code. The results vary only slightly among short and long methods, and among novice and advanced programmers. SEGMENT assists in making users obtain an overall picture of a methods actions and comprehend it quicker as well as provides hints for internal documentation placement.

Paper Link