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. 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

 * Review Programming style.
 * Review Naming convention (programming)

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:
 * 1) 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?
 * 2) Select a source you trust and review the style guide. Note the following:
 * 3) * Maximum recommended line length
 * 4) * Line continuation character
 * 5) * Code block structure
 * 6) * Standard indentation
 * 7) * Blank lines
 * 8) * White space
 * 9) * Comments
 * 10) * Variable and function naming conventions
 * 11) 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?