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:
I wonder if instead of another builtin just to mark something deprecated it wouldn’t be better to add a builtin to attach an attribute, and the “deprecated” can just be an attribute value then.
I wonder if instead of another builtin just to mark something deprecated it wouldn’t be better to add a builtin to attach an attribute, and the “deprecated” can just be an attribute value then.
That sounds similar to various pragma/attribute issues, all of which I believe are rejected or closed.
@deprecated() has been merged, looking forward to trying it out! (… though not saying I look forward to writing code that I later have to remove, slowly and painfully, from my non-existent users…)
My (uninformed) guess is that it’s related to the same issues with lazy evaluation semantics that led to the std.Options split between fields and decls.
What happened is that I made an initial implementation based on the semantics in my original proposal. Andrew then suggested some changes which improved the utility of the feature, but had the side effect of making more complicated to implement correctly. Initially I didn’t realize the implications behind certain changes and so we merged an implementation that was not correct, which then got reverted.