According to a quick search of the zig repo, there are 27 files with /// Deprecated in them, most from the standard library.
Given that zig aims to enable maintainable software, what do you think about language features regarding deprecation?
An obvious non-language-level utility would be a third-party linter looking for Deprecated in doc comments.
What existing features of zig aid the maintainability of libraries and user code through deprecation cycles?
Some existing semi-related maintainability features I have found nice:
User code (and library code when refactoring) sometimes doesn’t need to change very much when types change from pointers to values, since fields of struct pointers can be directly accessed with ., like my_struct_pointer.my_field, which contrasts with C requiring the -> (arrow) operator.
An enum type can be changed to a tagged union typically without changes to user code in switches.
of course, status quo zig cannot do this bc std.Options does not have a deprecation_warnings field.
user code can do something like this today though:
const root = @import("root");
pub const aDeprecatedFunction = if (@hasDecl(root, "deprecation_warnings") and root.deprecation_warnings) {
@compileError("'aDeprecatedFunction() is deprecated, use aBetterName() instead!")
} else aBetterName;
pub fn aBetterName() { ... }
ETA – could also make “deprecation_warnings” an options module in one’s build.zig so that users of a library could opt into them as part of the build process.
I think for user code a build option is the way to go. If deprecation_warnings does become a std option, then it might make sense to use an enum instead of a bool: