r/ProgrammingLanguages • u/gingerbill • May 13 '26
The Aesthetic Problem of Namespacing
https://www.gingerbill.org/article/2026/05/13/aesthetic-namespacing/
35
Upvotes
r/ProgrammingLanguages • u/gingerbill • May 13 '26
10
u/erez27 May 13 '26
After using Julia for a bit, I became convinced that multi-dispatch is a fantastic way to solve this issue. It gives you all the brevity of methods (especially if you use syntax sugar like A.f(B) === f(A, B), and it adds very useful functionality on top of it.
28
u/hrvbrs May 13 '26 edited May 13 '26
why is private-by-default not good practice? The article just says “It isn’t” but doesn’t elaborate.
The answer to this is to prevent leaky implementations. If you have a method or field that exposes implementation details of the class and you don't want class consumers relying on those details, best make it private. The idea isn't to "hide" information (anyone can see it), the idea is to have those details not be relied upon. That way you can change the implementation if needed without changing the functionality and without notifying the class consumers.
An example of this is using a 128-bit int to store data and metadata all in a single type. You may want to split up the 128 bits into 8 lanes of 16 bits each, and designate each lane for something, say the first 4 lanes represent some kind of metadata and the last 64 bits contain the data. Then you provide functions like
getType(),setData(), whatever. How you structure your scheme is completely up to you; your consumers don’t need to know about that, because all they see are the public functions. Then if you decide you want to switch around the lanes or restructure your schemes, you can do that on your own without telling your consumers what you did. The internals are kept private.Now it’s time for you to ask yourself: Why do you need access to something private? They made it private for a reason, presumably to prevent implementation reliance as described above. In my experience, if you find yourself needing access to internals to get work done, you’re not doing it right.
4
u/L8_4_Dinner (Ⓧ Ecstasy/XVM) May 13 '26
From the blog article by the author of the "Understanding the Odin Programming Language" book:
That hold true for your typical academic project, but becomes far more challenging in projects built by a team over time. I too was once a Visual SlickEdit (etc.) fan, but as a tool, it didn't hold up to multi-developer projects -- at all.
I am reminded of the disk operating system for the Apple ][, which did not support directories, therefore directories were stupid features to ask Steve for. (I'm not saying that these are identical problems, even though both lend themselves to simple hierarchical organization using human-selected names. Obviously, it it were actually this simple, modern filing systems would probably support directories, which obviously they ... um ... uh ... never mind.)
This is both brilliant and useful, and an approach that I've quite happily used for decades. It's a shame that most languages that I use never bothered to add support for this.
To translate: Here is a tool that is useful, and here is the evidence, which is why I am agreeing that you should not be able to use it in most places that you want to.
I am just not sure that I understand the relationship here between the going-in assumptions, the collected evidence, and the conclusion here.
Onto Ginger Bill's blog:
I'd rather ignore the repeated call-outs to "aesthetics". This isn't a question of aesthetics, and talking about aesthetics distracts from the important aspects of the discussion. I don't know Odin, so it's silly for me (or anyone else who hasn't worked in it) to criticize its choices without some heavy disclaimers -- I do know that a language needs to hold together as a whole, as a design in toto. As such, rationales for inclusion and exclusion of features need to be understood as part of that whole.
I'm personally a huge fan of namespace support -- but I'm not a blind fan. I'd want to understand why it does or doesn't fit in Odin before making any judgments. And reading these two blogs (and lots of other rants and writings by Ginger Bill over the years) doesn't give me enough information to make any sound judgments, so in general, I'd defer to his wisdom as "the designer and keeper of the whole".
Public/protected/private made sense to me in C++, and to some lesser extent in Java. I do have to agree with Ginger Bill that "public by default" makes sense in most situations, and he does ask (and answer) the right question: "The question I always ask is: Who are you hiding code from? Yourself?!"
I actually like the idea of hierarchical namespaces inheriting their parent's visibility, be that public (a reasonable default), protected, or private. But that does bring up the question: What do these terms even mean within the context of a specific language. And here again, in the context of Odin, it seems prudent to defer to the designer and keeper of the whole.
I do know that library writers are the ones who transition to believing that everything should be private by default. This is because they want to ensure backwards compatibility by having as little surface area exposed as is possible. This is also a quite reasonable way to think.
This is nice to have out in the open. I do believe in making the "preferred approaches" both easy and obvious. I'm not convinced that making the unwanted approaches be painful is the approach I would take, but having them be relatively painful is a natural outcome of working to better support the desired approaches.
4
u/echoes808 May 13 '26
It probably stems from certain paradigms where information hiding is held crucial. I think there is some truth to it but I agree that the package-private should probably achieve same goals in majority of cases.
3
u/msqrt May 13 '26
Nice posts! I do wonder if a simple fix for the searchability issue would be to allow (force?) you to use the full name when defining something within a namespace: you'd write
world.add(orworld::add) instead of justaddwhen defining the function.3
u/esotologist May 13 '26
I've recently looked to css class standards for naming ideas and now (when using functional programming) usually stick with:
verb_Target_andClause_andClause
so like:
get_Value_atKey set_Value_atIndex parse_Code_withContext check_Value_isTrue init_Object_withName_andValue
Etc~
1
u/Main_Succotash_6298 May 14 '26
pure anti intellectualism
17
u/[deleted] May 13 '26
[removed] — view removed comment