Hi, so I recently got into zig (and systems programming as a whole) about 3 months ago and let’s just say I don’t know enough to know what’s considered best practice.
So let’s say you have a generic data structure… Something like an ArrayList and you want to write a function that performs an operation on two ArrayList, let’s say like an addition operation of sorts that adds the elements of two ArrayList and produces a new one, which implementation would be considered best practice;
fn add(comptime T: type, a: ArrayList(T), b: ArrayList(T)) ArrayList(T) {}
Or
fn(a: anytype, b: anytype) anytype {} where we infer the type using @typeOf and @typeName to determine if they’re compatible to be added
The first one looks kinda redundant to me cause a and b would be of the same type but it looks like what’s consistent with the standard library (at least I’ve seen such pattern in many functions) and the second one looks much more convenient but doesn’t look like what a good zig programmer should do.
I would be more than happy if someone could provide some answers to my question… Thank you