Skip to content
Ameen Abozaid
In reviewJNR-003-L02

Naming

  • Lesson 2 of 7
  • 11 min read
  • Junior
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, not calc2.
  • 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, and retrieve.
  • Rename with the IDE (Shift+F6 in IntelliJ), so every usage changes safely.
Draft outline details

Demonstration

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

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.