Lesson Plan: Chapter 14
Connecting to CSTA Standards
|6-8||Algorithms & Programming||Variables||2-AP-11||Creating 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.
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!
|Lower level students||Higher level students|
|Can enhance their A-Frame project with appropriately named variables||Can explain the reasoning behind their naming choices|
- 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.
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.
|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.|
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
a. Camel case
The full solution codebase can be found here
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.
|The student creates a creative prototype that includes a design for hardware, software, and at least one other sensor||The student creates a prototype that lacks creativity or one of the required elements||The 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.