The Importance of Coding Styles Within Industries Stijn Broekhuis University of Twente P.O
Total Page:16
File Type:pdf, Size:1020Kb
The Importance of Coding Styles within Industries Stijn Broekhuis University of Twente P.O. Box 217, 7500AE Enschede The Netherlands [email protected] ABSTRACT with camelCase [10, 13, 15,5]. However, in Python this There exist common conventions and styles that try to im- is often snake_case [17,5] which originates from the lan- prove the readability and maintainability of software code. guage C. It is common for industrial projects to work with these Besides different coding styles between languages, many coding practices. Teams adopt or adapt coding styles, IDEs (Integrated development environment) offer options and in some cases, they are mandatory. This means cod- to change these styles to fit the preference of the user. ing practices are an integral part of software development. When a project involves multiple people it can then result This research will try to find a greater understanding of in every user having their own coding styles. To solve this coding styles within industries. Firstly, a literature review problem a there exists a file format called .editorconfig1. of coding styles with non-semantic consequences and their Many IDEs allow their coding style settings to be over- effects was done. Then, a survey was used to find informa- written by a file named .editorconfig that is stored in a tion about how coding styles are used in companies and project. Since the file is within a project, all members of finding a difference in the coding styles by looking at the the project will have the same .editorconfig file and thus experience. Nearly all participants used coding styles such maintain a consistent coding style (because their IDEs will as Naming Conventions, Brackets and Indention rules. warn or even cause errors if they do not). To manage and fix bugs within code, it must be read- Keywords able. It is known that some coding practices affect the readability of code [1,2,8] in both positive and nega- Coding Conventions, Coding Styles, Programming tive ways. For a company it is useful to have conventions that improve the readability of their code. Coding styles 1. INTRODUCTION with non-semantic consequences are styles that do not af- The skills of a good programmer are not something to fect how the code operates, it only affects how code looks. be taught. Learning to write good code is achieved often This study focuses on the non-semantic consequences as by starting with reading good code. Making code read- it interesting to see the reason why they are used. Other able is, therefore, an important factor in programming. styles that have semantic consequences are useful as they Besides being able to make better code, readable code is can improve the code's speed, testability, maintainability, essential for programmers that work in a team to work to- or debugability. It is expected that developers in indus- gether. As everyone needs to be able to understand what tries have higher standards for clean code than a project sections of code do without spending too much time. As made by a single person. The goals for this research are a result, coding conventions and styles were made. One as follows: of the first coding standards is the book "The Elements of Programming Style" [6] written by Kernighan, Brian W. Goal 1: Develop a greater understanding of the effects of and Plauger, Phillip James. The book showed examples coding conventions and the common differences in of real programs and how they could be improved. Many popular languages. of the 'lessons' that Kernighan and Plauger stated, such as; Say what you mean, simply and directly. and Write Goal 2: Develop a greater understanding of the impor- clearly - don't sacrifice clarity for "efficiency." are still rel- tance and usage of coding styles with non-semantic evant today. consequences in industries. Coding styles such as the location of a 'f' or using spaces To achieve these goals, the following research questions around operations, do not have an objective reason why (RQ) are used as a basis: some are better than others. These are often based on preference and what is common in the language. In Java, the naming conventions of variables are usually written RQ1: In what areas do non-semantic coding styles differ in popular languages such as Java, Python, JavaScript Permission to make digital or hard copies of all or part of this work for and C#? personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that RQ2: How do non-semantic coding styles found in RQ1 copies bear this notice and the full citation on the first page. To copy oth- influence the quality/readability of the code? erwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. RQ3: How do employees of industries use coding styles 35th Twente Student Conference on IT July. 2nd, 2021, Enschede, The found in RQ1? Are they aware of the influences Netherlands. found in RQ2? Copyright 2021, University of Twente, Faculty of Electrical Engineer- 1 ing, Mathematics and Computer Science. Learn more: https://editorconfig.org/ 1 This study conducted literature research and a survey to of individual coding styles. This will give an understand- find out how coding styles are generally used. The sur- ing of the importance of individual coding conventions and vey will ask employees what coding styles and conventions styles. Answering this question allows the research to con- they use and their experience and opinion about using tinue with the next and final research question. them. The results will give insight into the frequency and RQ3 will be answered with a survey that will be given to necessity of coding practices and how they are executed. employees of different industries using Google Forms. The survey will have three sections. Firstly, general questions 2. RELATED WORK about what type of work they work in, how long they have This section contains related work about coding conven- worked, and what language they work in. Secondly, this tions. Coding conventions have been proposed since the section will focus on questions about coding styles. These 1970s. Well known examples are authors are Kernighan coding styles will not be connected to specific languages. and Plauger. Most papers focused on semantic conse- Thirdly, there will be a section about coding conventions quences, although some did partly focused on readability. and their effect on the quality of code according to the par- In 1974, Kernighan, Brian W. and Plauger, Phillip James ticipants. Finally, with the answers found in the research [6] published the first edition of The Elements of Program- questions, the goals will be completed and a conclusion for ming Style. According to them, it has been common for each of them can be made. programmers to make unreadable code that was a pain to maintain, so-called 'write-only code', but "...students, 4. THE CODING STYLES teachers, and computing professionals now recognize the To find common areas that coding styles differ, one has importance of readable programs." The book gave many to look at coding style guides. The research found cod- lessons on how to write quality code by using examples of ing guidelines by using the search engines DuckDuckGo real software and improving them. and Google and using the terms "Coding Style Guide" and In 2016, H. G. Koller [7] wrote in their master thesis about "Coding Conventions Guides". Six guides were chosen. the effects of Clean Code on understandability. Their re- These were based on the most used languages [4]. Using search showed, unexpectedly, little effect on the under- six guidelines gives an accurate representation of popular standability when using Clean Code. Using Clean Code languages and what areas coding styles are often used. only had a positive effect on how long changing current Google Style Guides functionality took. The Google Styles Guides [5] are a collection of style guides In 2018, R. M. dos Santos and M. A. Gerosa [2] experi- that are used by Google and serve as a guide for program- mented with certain coding practices and the impact on mers within the company who add to Google's code or for the readability of the code. Their research found that of external programmers who wish to create a project that the 11 assessed coding practices they tested, 8 had evi- has the same style as Google. Because this is a collection dence that it affected readability. of style guides, the study looked at the style guide of pop- ular languages[4]. Unlike humans, the style guides have In 2021, V. Lenarduzzi, V. Nikkola, N. Saarim¨aki and D. Taibi [9] researched the effects of code quality on pull re- similar reasons for their existence. They help program- quest acceptance. They wanted to find out if GitHub pull mers to make code readable and/or look better. However, requests had a higher chance of being accepted if the code these are not rules, one is not required to follow them. If was clean. They concluded that code quality does not there is a scenario where violating the guidelines results in affect the pull request acceptance. better code, then these rules do not apply. Additionally, style guides might be wrong on certain rules and forcing is therefore not a favourable idea. 3. RESEARCH METHODOLOGIES Answers to the research questions mentioned above need Style Guide for Python Code 2001 to be found to achieve the goal of the paper. In Figure1 The Style Guide for Python Code [17] is part of the Python is a simple diagram of how the research questions relate.