Entity name collision and scope of variables, constants and functions

Or japanese: wa to declare variables, ga to refer to them :slight_smile:

3 Likes

@vulpesx , @LucasSantos91 -

It is a case of old habits that needs a significant shift as nearly every other language there uses -1 is an index to signal that it is not found.

I could list them, but it is not only a very long list, but I am sure you know as well as I do.

On isize and usize, yes it is a pain to cast, but practically strings can (in my world) never get to usize in any case; so I am referring back to old style C on int for most genetic pieces of code - again - I take your points - there are better ways now; but easy to fall as a noob in that trap as most other mainstream languages still have that route.

Only thing is - i believe - that a null uint is twice the size of a uint.

It crossed my mind as well… I guess it is a case of adopting wholeheartedly what you get into, and forget the small-change concerns in favor of safety and consistency.

After a week of playing around with naming/naming conventions I have come to the realization that was bothering me…

m_ for member variables, really don’t like it.
snake case locals, don’t like it that much either
_arg for arguments (hate it)

And all that (and other attempts) while my code just didn’t feel/read right.
Then I remembered one of the fundamental reasons why I looked at Zig was its method and data encapsulation into structs-like (file, enum etc) classes.

So I converted all loose code into ā€œstructsā€; and basically any place that a name reads bad, I assess whether it should be encapsulated.

This makes the code much more readable as the naming conventions are really simple, all values (variables, constants) etc are very short - as it is determined by a namespace (like Java, Kotlin, DotNet etc). This is surprising simple and gives good organisation (for me anyway).

The only issue is that my IDE does not yet support Zig refactoring - so this is way more painful than it should be. And, like the framework, I abbreviate locals where obvious.

3 Likes

My vscode is verrrrrry bad refactoring zig code.
Glad I don’t use it for huge projects.

4 posts were split to a new topic: Short math notation, casting, clarity of math expressions