I am brand new to Zig - admire and enjoy it even though there is a deceptive learning curve to it. Used to most of the basics like tooling, pointers, syntax and library etc but one thing catches me off guard that I think I know the Zig answer to, but don’t like it.
Is there a way to specify scope to a variable. To give you an example,
I work on a “class” struct, and it grows. In order to have sanity, I have a single noun parameter called count, in many places. This works perfectly, until, a few days later, I have to have a function called count.
The function name count makes sense in context, and since size, len is already used or implied/connected to other things means that I am running out of nouns for a length of an item - meaning depending on my choice I may have to change something in many places.
I do appreciate the fact that Zig is doing this to avoid collision as function references can be used “like variables” and various others, but - and I will be happy if there is a qualifier that I am missing, but it is a huge shortcoming to me in a modern language that I cannot qualify where a name comes from.
pub fn clash(count: usize) void {
std.debug.print("{}}", count);
}
pub fn count(self: *Self, str: []const u8) usize {
const c= std.mem.count(u8, &self.buffer, str);
return c;
}
src/utils/pascalstring/PascalString.zig:34:18: error: function parameter shadows declaration of 'count'
pub fn clash(count: usize) void {
^~~~~
src/utils/pascalstring/PascalString.zig:59:9: note: declared here
pub fn count(self: *Self, str: []const u8) usize {
~~~~^~
I already follow the Zig naming conventions, which I have no issue with. For single syllable nouns however, the naming does not differentiate. I know various other languages has/had this issue - and the “end-user” developers solution to that was usually (very) ugly and counter intuitive e.g. Hungarian notation to parameters.
I obviously want to avoid that. I also want to avoid over-complicating local variables, and even worse, notating or abbreviating parameters, variables or any other types.
Am I missing some trick, is it a concern to others, or is the way it is going to be forever and make my own a long term plan.