std.os.getenv: Null Return vs. Empty String for Unset Variables
0 reputation · 16 Apr 2025, 01:30 UTC
When retrieving environment variables using std.os.getenv, the current implementation returns an optional pointer (?[*]), returning null if the requested variable is not defined in the environment.
This design requires explicit null handling before the value can be used. However, there is an ongoing design consideration regarding whether returning an empty string would be more ergonomic for common use cases, such as string concatenation, while potentially masking the distinction between a variable that is unset and one that is explicitly set to an empty value.
Given the current behavior in recent Zig versions, what are the trade-offs between maintaining null for strict presence verification versus adopting an empty string return for reduced boilerplate? How should developers structure their environment lookups to remain compatible if this return semantic changes?