To Camelcase Or Under Score
Total Page:16
File Type:pdf, Size:1020Kb
To CamelCase or Under score Dave Binkley† Marcia Davis‡ Dawn Lawrie† Christopher Morrell† †Loyola College ‡Johns Hopkins University BaltimoreMD BaltimoreMD 21210,USA 21218,USA [email protected] [email protected] [email protected] [email protected] Abstract A recent trend in style guides for identifiers is to favor Naming conventions are generally adopted in an effort camel casing (e.g., spongeBob) over the use of underscores to improve program comprehension. Two of the most pop- (e.g., sponge bob). However, natural language research in ular conventions are alternatives for composing multi-word psychology suggests that this is the wrong choice. For ex- identifiers: the use of underscores and the use of camel cas- ample, a study by Epelboim et al. [6] considered the ef- ing. While most programmers have a personal opinion as fect of the type of space filler on word recognition. They to which style is better, empirical study forms a more appro- found that replacing spaces with Latin letters, Greek letters, priate basis for choosing between them. or digits had a negative impact on reading. However, shaded The central hypothesis considered herein is that identi- boxes have essentially no effect on reading times or on the fier style affects the speed and accuracy of manipulating recognition of individual words. A shaded box depicts a programs. An empirical study of 135 programmers and space in a similar way to an underscore. In informal dis- non-programmers was conducted to better understand the cussions, psychology researchers assert that camel casing impact of identifier style on code readability. The experi- should increase reading difficulty. ment builds on past work of others who study how readers This suggests that underscores should be preferred over of natural language perform such tasks. Results indicate camel casing as an identifier construction style. However, that camel casing leads to higher accuracy among all sub- given that camel casing is currently favored in the program- jects regardless of training, and those trained in camel cas- ming community, perhaps something in the software devel- ing are able to recognize identifiers in the camel case style opment process differs from natural language reading. Al- faster than identifiers in the underscore style. ternatively, perhaps programmers can be trained to perform with either style. To properly understand the issue and an- swer these questions requires empirical study of both pro- 1 Introduction grammers and non-programmers. The non-programmers Over the past three decades, the software development provide a control group for studying training. This paper process has moved toward greater engineering discipline. presents results from such a study, which considers the abil- Initially this appeared in the form of rules for structuring ity to discern closely-related identifier names. the control flow of a program. An example is the exclusive The research presented herein is part of a project aimed use of single exit loops. Over time such rules have been in- at understanding how programmers process the natural- tegrated into some programming languages. For instance, language information held within source code. The goal in the Java language, the much debated goto statement has of this experiment is to better understand the readability of been removed [5, 18, 16, 10]. Object-orientation brought identifiers. The central hypothesis considered is that identi- similar kinds of rules to the structuring of data. However, fier style (the use of underscores or camel casing) affects the language designers have been understandably hesitant to speed and accuracy of manipulating programs. For exam- eliminate legacy programming language constructs. This ple, the effect would be negative if long camel-cased identi- has lead to the introduction of coding standards [7, 11, 12]. fiers lowered readability by interfering with saccadic iden- One area where programmers are given considerable tification (eye landings). syntactic freedom is the construction of identifier names. The remainder of the paper first presents some necessary Excessive liberty in the use of this freedom interferes with background information in Section 2 before describing the source-code understanding, especially when code is trans- experiment’s design, the four hypotheses considered, and ferred from one engineer to another. This has allowed a the results in Sections 3, 4, and 5, respectively. This is fol- wide range of proposed conventions and standards for iden- lowed by a discussion of related work in Section 6. Finally, tifier construction [4, 3, 19]. Section 7 summarizes the paper and suggests future work. 1 2 Background the value of another explanatory variable. For example, if Training interacts with Style in a model where Time is the This section describes three things: first, researchers cur- response variable, then the effect of Training on Time de- rent understanding of how reading is performed, findings pends on Style (i.e., is different when using camel casing from two prior motivating studies, and finally, the statis- than when using underscores). Backward elimination of tical techniques used in the analysis of the empirical data statistically non-significant terms (p > . ) yields the fi- gathered during the study. Current theories of eye move- 0 05 nal model. Note that some non-significant variables and ments while reading assert that reading saccades (essen- interactions are retained to preserve a hierarchically well- tially where the eye lands when one is reading) are pro- formulated model [14]. grammed primarily on the basis of information about the A second modeling technique is needed when the re- length of the upcoming word. This is determined by low- sponse variable is a binary variable and thus standard level visual processes that detect spaces to the right of fixa- mixed-effect models are not appropriate. In this case, Gen- tion point [6]. eralized Linear Mixed Models (GLMM) are required [13]. In the first study discussed in this section, Epelboim et Such models correctly account for repeated measures while al. considered the impact of different inter-word fillers on providing a model for the probability of the binary outcome word recognition [6]. Fillers, because they cause lateral (e.g., the probability of correctness). The models were fit distraction, have a detrimental effect on reading speed. The using proc nlmixed provided by SAS 9.1. study compared reading using four fillers and seven filler In more detail, to model response variable Correctness placements within English prose. The three combinations using a set of explanatory variables X , the model estimates of interest are normal (e.g.,“sponge bob”), un-spaced (e.g., i ■ the probability, p, of a success by modeling the log odds: “spongebob”),and shaded-box filled (e.g.,“sponge bob)”. p From a visual perspective, the un-spaced text is similar ln = β0 + β1X1 + ... + βkXk 1 − p to camel casing except that camel casing might be expected Here the interpretation of the parameter estimates, β , is not to be easier to read because of the added clues provided by i as straightforward as in linear regression. The interpretation capitalization to aid in fixation. The use of a shaded box is of the estimated β (say b ) is that the estimated log odds, most similar to the use of underscores where, again, under- i i ln( p ), increases by b for a unit increase in X . Thus, scores might be expected to be easier to read because they 1−p i i for these models the parameter estimate, p-value, and odd are more similar to spaces. Overall, Epelboim et al. found ratio, ebi are reported since ln( p ) = b is equivalent to that shaded boxes did not have an impact on word recogni- 1−p i p ebi . tion time (p > 0.3) while all other fillers did (p < 0.05). 1−p = In addition, the impact on reading speed was more dramatic For example, consider a model that includes the influ- for more difficult text. ence of the time a subject spends completing the demo- The second study discussed in this section was con- graphics screen Time On Demographics on Correctness. In ducted by New et al. and used information from the En- this model the coefficient, bi, for Time On Demographics is glish Lexicon Project. It showed that longer words required 0.07089. Assuming that this is the only explanatory vari- able in the model, the odds ratio of being correct for a unit significantly more time to determine their validity as actual 0.07089 words (greater lexical decision making time) than shorter increase in Time On Demographics is e = 1.073, so words [15]. One possible explanation for this phenomenon the odds of being correct increase by 7.3% with each addi- is that longer words require more fixations (landings of the tional second spent on the demographics screen. eye) before they can be recognized and correctly classified. This slows reading and thus negatively impacts comprehen- 3 Experimental Design sion. To investigate the impact of style, the study evaluates the Finally, two statistical modeling techniques are used. speed and accuracy of subjects searching for a given identi- The first, linear mixed-effects regression models, is appro- fier. The particular task the subjects encounter is presented priate when the data includes repeated-measures and miss- as a game to help motivate participants, especially the non- ing values (e.g., due to subject drop out) [20]. These sta- programmerpopulation. A subject first encounters a phrase, tistical models allow the identification and examination of which is read. On the subsequent screen four clouds move important explanatory variables associated with a given re- around the screen. Each cloud contains an identifier written sponse variable. in one of the two styles under investigation. Only one of the The construction of a linear mixed-effects regression clouds contains the exact same phrase.