Conventions in Code Writing

Objective: Students will be able to recognize and utilize a variety of conventions used in code writing.

Key Terms: Convention, audience, discipline field, code, stylistic choice.

Timing: These lessons could be particularly appropriate in any course where students are learning to write code, or in any course where students are learning to write code so that it can be more easily digested by other humans. 

Part I: Basic Code Writing Conventions

  1. Consider this Style Guide that is specific to the language Julia, this Python Pep 8 style guide, or any other style guide that is relevant for the language you want your students to work in.
  2. Assign the guide to students, as well as a piece of code of your choice that is tailored to your course. Students could do this work inside or outside of class. This could be, for example, a sample of anonymized student work, or a purpose-written sample that you create. 
  3. Put the students into small groups
  4. Have the students evaluate the sample code based on the conventions in the guide, and answer the following questions in their groups.

Questions about coding conventions

  • Did the writing follow all of the suggested conventions?
  • If places where it did not, did this affect the computational efficiency or the clarify of the writing? If so, how?
  • Do you have any ideas why the author did not follow the conventions in those places?