Eliminating the intrusive interface copy footgun in userland via an opaque representation

All afternoon I’ve been pulling weeds and wishing I could retract this. It’s not really how I feel deep down, after all. I have nothing against _prefixing, but (in Python, which also doesn’t have the concept of “private”) I don’t think of it as shouting “private”, but “not envisioned for your direct use”. Or, “if you’re inspecting this file of code to understand how to use it, you can basically ignore these implementation details (variables and methods), and just focus on the rest". NOT “better keep your hands off my private stuffs!” Well, here, with intrusive interfaces, we have exactly the opposite - you ARE supposed to use the interface! So the “getter function” would just be the way to hand over the proper form of the interface (the address, that is).

While I have nothing against _prefixing, I do vehemently dislike “getter” and “setter” functions. It has something to do with the OOP tinge, sure, but there are other reasons. In short, I “like it how it is” with zig Reader/Writer intrusive interfaces. But… maybe it could still be slightly tweaked…? What one really always wants is the pointer to the interface, so, would it make any sense to make the type of interface *Reader instead of Reader? This is an underdeveloped brainfart, though. Quick consideration at least reveals “unnaturalness” within the implementation (e.g. File.Reader.initInterface()). But I guess the idea should be shot down with more robust ammunition.

My 2 cents: too much bike shedding and things that have been discussed over and over…, I will just wait for compiler support for more safety-check like things to catch the error for beginners and for non-beginners I don’t expect them to make this mistake regularly anyway

8 Likes

Thinking about it some more and taking into account the feedback here, I don’t think I stand behind my own idea anymore. It is basically emulating private fields in Zig in a convoluted way (that risks hindering compiler optimizations on top) and, as has been mentioned multiple times in the thread, a beginner will make this mistake probably once, and then never again. The planned runtime safety check should be more than enough to help with this. Moreover, an API design like this hides what is actually happening under the hood, which hinders those same beginners’ ability to learn – an antithesis of what I actually think is right.

Thus, I hereby retract this “proposal” (and I’m adding a note to the top of the OP to make it clear) :slight_smile:

4 Likes