I think it’s mostly a matter of preference, but my argument against it would be that I find it nice to know immediately that you have reached a minimal abstraction provided by the language, rather than seeing a function call that looks like there may be some value to looking at the definition of.
Another related question (I know so little).
IF I would do that for a few of these, is it possible to have this functions available in the whole project without explicit @import everywhere?
No, as far as I know there is no way to do that, I also think it isn’t wanted, because it would lead towards hard to understand code, where everyone has their own magically appearing utility functions (and everyone has different ones).
I guess you could create editor tooling that automatically creates a declaration for specific things in every file where you use it, so it would automatically add something like this:
Most non-trivial projects end up with a bucket for stuff used in many files, right? I call those common.zig.
So it’s just
const common = @import("common.zig");
const cast = common.cast;
Of course it would need to be pub inline fn, but this poses no problem.
The function itself is also three lines, so I’ll toss it at the bottom of a file as soon as I start casting. Maybe it gets moved if I need to use it in a lot of places.
Correct, that’s an example of something which has to be a builtin. Neither @as nor @intCast can be implemented in user space. But the mere combination of the two clearly can be.
Going back to the sanity of doing this for cosmetic reasons, it’s worth nothing that the standard library already does this with some simple functions like cosZig Documentation. Up to you if that is more reasonable than @cos.