Lesson Plan: Chapter 14

Connecting to CSTA Standards

GradesConceptSubconceptStandard NumberPractice
6-8Algorithms & ProgrammingVariables2-AP-11Creating Computational Artifacts: 5.1, 5.2

Create clearly named variables that represent different data types and perform operations on their values.

A variable is like a container with a name, in which the contents may change, but the name (identifier) does not. When planning and developing programs, students should decide when and how to declare and name new variables. Students should use naming conventions to improve program readability. Examples of operations include adding points to the score, combining user input with words to make a sentence, changing the size of a picture, or adding a name to a list of people.


Learning Outcomes/Goals

By the time they reach this chapter, students have already experimented with variables, for example when working with the Micro:bit or MakeCode Arcade. In this chapter, however, they start to think more deeply how to name variables appropriately, and to think about naming things in general when working with code - arguably one of the hardest things to do as a programmer!


Differentiated Instruction

Lower level studentsHigher level students
Can enhance their A-Frame project with appropriately named variablesCan explain the reasoning behind their naming choices

Transfer Learning

Students could go on a scavenger hunt in Open-Source repos on GitHub to understand how various languages have different naming conventions and map a taxonomy, perhaps comparing languages such as Go, Java, and JavaScript.


Vocabulary

  • Constant: A type of variable that does not change.
  • DOM: The Document Object Model, a tree-like structure that describes the layout of a web page.
  • DRY: "Don't Repeat Yourself" - a tenet in development that encourages developers to rewrite their code so that it is less repetitive.

Assessment

Students can be tested on their understanding of refactoring code and fixing poor naming conventions. Given a piece of code, or choosing a sample from GitHub, they can demonstrate their mastery of the concepts.

FormativeSummative
Research how various languages enforce DRY practices, naming conventions, and other normative features. Write a taxonomy of some of a language's patterns.Write a summary of some aspects of a given language's naming conventions and code best practices.

Quiz Answers

Q1: Variables should be named so that

a. They are easier to use in code

b. It’s easy to understand what they refer to

c. They can be more easily used in functions

Q2: DRY in software development refers to:

a. Don’t cause infinite loops

b. Don’t repeat yourself when writing code

c. Don’t write random variable names

Q3: In JavaScript, Constant names are most often written in:

a. Camel case

b. Uppercase

c. Lowercase


More Resources/Materials


Solution Code

The full solution codebase can be found hereopen in new window


Assignment and Rubric: Code Hunt

In this chapter, you worked to refactor your code and make it more DRY. Go back over other assignments from this book, from a different coding project, or even from someone else’s code on GitHub, and improve it. Use the techniques you learned in this chapter to rename variables and functions according to best practices and refactor the code to avoid repetitions. Present a “before and after” view of your work using the worksheet provided.

ExemplaryAdequateNeeds Improvement
The student creates a creative prototype that includes a design for hardware, software, and at least one other sensorThe student creates a prototype that lacks creativity or one of the required elementsThe student creates only a basic prototype that lacks sophistication

*tip: prior to saving as a PDF, select the 'light' mode at the top using the 'sun' icon.