June 20, 2010
June 20, 2010
June 23, 2010
Computers in Education
15.281.1 - 15.281.11
Coding Practices for Embedded Systems
Abstract Far too often, students focus on creating a working project without any regard for the quality, readability, and maintainability of their code. Students are not usually made to realize how learning and applying good coding practices can improve the success of their projects and make them more valuable to future employers. By adhering to a set of simple coding practices, students can create projects that are easier to read, maintain, predict (no unexpected features or “ghost” effects), and reuse. Many students have developed a misconception that a copious amount of commenting can make up for the shortcomings of code that is poorly organized and/or difficult to understand. Although good commenting is important and can make the purpose of code blocks clearer, paragraphs of explanation do more to clutter a project than they do to improve its quality. Proper commenting should be used in conjunction with other important practices in order to create a project with the cleanest and clearest code possible. Distinctive naming of components (files, variables, constants, etc.) and a logical layering of code can help to make changes to code far simpler, less time-consuming, and produce more predictable results. This paper provides a guide to good coding practices. Some of the topics covered will include proper use of commenting, code modularization, layering, descriptive naming, cohesion, and avoiding race conditions.
Introduction The standard for many embedded systems courses is to stress the importance of functioning code. Although the primary goal of a design is to obtain a functioning product, students should be taught the importance of good coding practices as well. Many programs stress the need for good commenting but fail to cover the other guidelines. As a result, students fall under the false impression that a novel's worth of commenting can compensate for bad code. Coding should be taught in a similar fashion to writing an essay. The writing process is done in multiple iterations of review and refinement. Students should first write functioning code that meets specification. Then, they need to review and edit their code until they have achieved the best possible solution (i.e. most readable, reusable, maintainable, and predictable code). By following a simple set of rules, students can create code that is easy to read, maintain, predict, and reuse. Obtaining this valuable skill will make them more valuable to future employers and save them valuable design, debug, and test time. The following sections cover basic coding practices and the reasons for adhering to them.
Commenting One of the most commonly overlooked and most important coding practices is the commenting of finished code. Comments are usually added as an afterthought with little or no effort made on the part of the programmer to make clear, concise statements about their design. One should always consider the consequences of poorly commenting code or leaving out
Pook, M., & Loo, S. M., & Planting, A., & Kiepert, J., & Klein, D. (2010, June), Coding Practices For Embedded Systems Paper presented at 2010 Annual Conference & Exposition, Louisville, Kentucky. 10.18260/1-2--16347
ASEE holds the copyright on this document. It may be read by the public free of charge. Authors may archive their work on personal websites or in institutional repositories with the following citation: © 2010 American Society for Engineering Education. Other scholars may excerpt or quote from these materials with the same citation. When excerpting or quoting from Conference Proceedings, authors should, in addition to noting the ASEE copyright, list all the original authors and their institutions and name the host city of the conference. - Last updated April 1, 2015