Default Arguments and Domain Policy

A default argument fills in an omitted parameter. The default should represent a documented choice that is appropriate for the function's typical use.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Choose the missing behavior
  2. Notice behavior across calls
  3. Name what omission actually means
  4. Keep the resolved policy inspectable

Choose the missing behavior

A rounding routine might default to two displayed digits. Passing zero then requests a whole-number display. Preserve that choice explicitly rather than relying on truth testing, since zero has a meaningful result.

Notice behavior across calls

A report default based on today's date should generally compute that date at invocation or receive a date explicitly. In Python, writing the call to get today's date in the parameter declaration captures it when the function is defined. Mutable defaults illustrate the same evaluation timing.[1][2]

Name what omission actually means

A library exporting measurements may use precision=2 to mean two digits after the decimal point. With a reading of 13.874, omission yields 13.87 while specifying zero can yield 14. Applying precision or 2 silently makes the zero-digit option impossible. Decide whether None means a machine-readable export with no rounding, an inherited system setting, or an invalid input, then use an explicit check. See missing, empty and zero values for other places where an omission differs from an explicit choice.

Keep the resolved policy inspectable

During a move from a local export to an external job, the receiving worker may run with a different default. If repeatability matters, save or send the resolved precision along with the job. A documented change from two digits to three may also change downstream snapshots. Test the omitted case, explicit zero and a non-default choice against a value whose third digit changes the display. See changing function contracts for managing callers that rely on an established default.

References

  1. Python Software Foundation, Python Tutorial: Control Flow ↩
  2. Python Software Foundation, Python Language Reference: Execution Model ↩