Key Terms

  • left-to-right associativity: the rule that operators with the same precedence are evaluated from left to right in an expression
  • magic number: a hard-coded number in a program that lacks context or explanation, making the code harder to understand and maintain
  • named constant: a variable with a value that is set once and cannot be changed; it is used to give meaningful names to fixed values
  • overhead: the extra processing time, memory, or other resources required by a computer program beyond the actual task it is performing
  • rules of precedence (order of operations): the rules that define the sequence in which different operations (like addition and multiplication) are performed in an expression to ensure consistent results

In a quiet village called Codeville, a young coder named Lex was building a calculator app.

One day, Lex wrote this line in her code:
total = 5 + 3 * 2


But when she ran the program, the result was 11, not 16 like she expected! That’s when her mentor, Ava, stepped in and said,
“Lex, you need to understand the rules of precedence—multiplication comes before addition!”

So Lex corrected her thinking and realized the expression was evaluated as 5 + (3 * 2).

But there was another problem. She found a line deep in her code that looked like this:
if score > 42:


“Why 42?” her friend asked. “What does it mean?”
Lex scratched her head. “I don’t know… it’s just always been there.”
“That’s a magic number,” Ava explained. “It has no meaning to others. Replace it with a named constant like this:
MAX_SCORE = 42
if score > MAX_SCORE:


Now her code was much clearer!

Later, she added a complex formula using multiple operators, like x – y + z, and Ava reminded her,
“Don’t forget about left-to-right associativity! Since – and + have the same precedence, the program will evaluate them from left to right.”

Finally, when Lex tried to add too many features—like sound effects, animations, and real-time stats—her program got slow and buggy.
Ava shook her head. “That’s too much overhead. All that extra stuff is weighing the program down. Focus on the core task.”

From that day on, Lex wrote cleaner, smarter code—and always remembered the wisdom of Codeville’s key terms.