Programming Fundamentals/Functions/Style
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
edit- 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
editIntroduction
editQuestions
edit- 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
editWith 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
edit- 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?