Always define explicit configuration defaults rather than relying on implicit behavior or autovivification. Configuration values should: 1. Use explicit nil defaults instead of undefined values
Always define explicit configuration defaults rather than relying on implicit behavior or autovivification. Configuration values should:
Example:
# Bad - Implicit default
property :store_location, String
# Good - Explicit default with clear documentation
property :store_location, String,
default: nil,
description: "Use the `CurrentUser` store instead of the default `LocalMachine` store."
# Bad - Environment variable configuration
default :use_s3_cache, ENV['USE_S3_CACHE'] == 'true'
# Good - Chef::Config configuration
config_context :caching do
default :use_s3, false
end
This approach improves code clarity, makes behavior more predictable, and ensures proper documentation of configuration options. It also facilitates better testing and maintenance by making all possible states explicit.
Enter the URL of a public GitHub repository