Naming
On This Lesson 4 topics
The content for this lesson is written and waiting for review. The outline below shows what it covers. It will be published once it is approved.
In this lesson
name things so the code reads as intent.
Planned topics
- A name says what, not how:
totalWithTax, notcalc2. - Classes are nouns (
Cart); methods are verbs (addItem); booleans read as questions (isEmpty). - Avoid abbreviations and noise words like
Manager,Data,Info. - One word per idea: do not mix
get,fetch, andretrieve. - Rename with the IDE (Shift+F6 in IntelliJ), so every usage changes safely.
Draft outline details
Demonstration
// before
double calc(double p, int q, double d) { return p * q - d; }
// after
Money lineTotal(Money unitPrice, int quantity, Money discount) { ... }Check your understanding
Better name for boolean flag that says a cart has no items?
Show answer
isEmpty.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.