Curriculum

Curriculum

Give Business Limits a Clear Constant Name

Scenario

The library decides to raise its borrowing limit from 3 books to 4 books.

Selected choicePick a choice below
Result—

Try it yourself

Compare raw magic numbers against a named constant when a rule changes.

Reveal the explanation
  1. Code repeats raw "3" in checker, message, and tests

    Fragile. Updating one "3" to "4" while forgetting another creates contradictory behavior.

  2. LIMIT = 3 (no unit or meaning)

    Still unclear whether 3 means books, days, or rooms.

  3. MAX_BORROWED_BOOKS = 3 -> borrowedCount < MAX_BORROWED_BOOKS

    Self-documenting and centralized: one update keeps rule and checks aligned.

A clear constant name states both what is being limited and its unit (for example PASSING_SCORE = 60 or MAX_ROOM_CAPACITY = 12).

Review first

Your turn

Replace the magic numbers in "score >= 60 and score <= 100" with two well-named constants.

Common mistake Naming constants NUM_1 and NUM_2 instead of describing the rule.

Check your work

PASSING_SCORE = 60 and MAX_QUIZ_SCORE = 100; score >= PASSING_SCORE and score <= MAX_QUIZ_SCORE.

Quick check

Which constant name best describes the maximum number of seats in a study room?
Show the answer and reasoning

Correct answer MAX_ROOM_SEATS

MAX_ROOM_SEATS tells any reader both the limit role and the unit being counted.