< Programming Fundamentals < Functions

Code formatting
Programming style is a set of rules or guidelines used when writing the source code for a computer program. Following a particular programming style will help programmers read and understand source code conforming to the style, and help to avoid introducing errors.[1] This activity introduces programming style and will help you apply standard programming style in a program.
Objectives
- Understand programming style.
- Recognize standard programming style for your selected programming language.
- Use a programming-style checker (linter) to validate programming style for a program.
Prerequisites
Introduction
Questions
- What aspects of programming would you want to include in a standard style guide?
- What is a naming convention?
- What naming convention is used in the programming language you are using for this course?
Activity
With a partner, perform the following:
- Research "_____ style guide", where _____ is your selected programming language. There are typically multiple style guides available for a given language. Which source do you trust? Why?
- Select a source you trust and review the style guide. Note the following:[2]
- Maximum recommended line length
- Line continuation character
- Code block structure
- Standard indentation
- Blank lines
- White space
- Comments
- Variable and function naming conventions
- Search for a linter or code beautifier for your selected programming language. Run the tool on a program you have created to test your code formatting.
Applications
- What are the advantages of having a standard programming style for a given programming language?
- What tool can you use to validate your programming style, and when will you use this tool?
- Discuss your activity experience with your classmates. What surprised you? What have you learned that you can apply to your own school or work environment?
References
This article is issued from Wikiversity. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.