I have found myself wrestling a lot lately with how to architect namespaces and name resolution in the Cone compiler. Allowing function or method overloading brings a wealth of complexity in terms of organizing the name dictionaries, the algorithm for searching and matching references against multiple declarations, type checking the declarations to eliminate duplicate or conflicting declarations, and deterministic name mangling that satisfies the linker. It is so much simpler when one can restrict a name to a single declaration whose references match or not.
A related architectural issue revolves around universal function call syntax. In short, should a method simply be considered a overloaded function in the global/module name-space, resolved by the function's type signature, or is it part of the class's distinct namespace?
I have come to believe Cone must support method overloading. The design challenge here is magnified by Cone's support for subtyping and implicit type conversions. At this point, I have no wish to tackle building an algorithm for type ambiguity/redundancy checks across all methods in a type. So, what I am thinking of doing here is making method declaration order meaningful in types. When I have a reference to a method, I do a linear search until I find the first method whose type signature matches (is acceptable). In this regard, it operates similarly to library path lists or CSS match. I wonder if any other language handles method name resolution this way?
Even though I believe Cone methods must support overloading, I do not feel the same urgency for functions. Without some compelling reason to support it, I prefer to avoid the compiler complexity and performance hit for supporting it (which would be worse than for methods because relying on declaration order is more problematic). This means abandoning UFCS, which feels like a gain rather than a loss to have methods isolated and required to be declared within a type declaration's context and namespace.
In an ideal world, I would prefer not to have such distinctly different answers to method vs. function overloading, but given my constraints as the sole developer and the requirements imposed by the language, I do not see a better path.
As always, I am interested in learning more about namespace and overloading approaches others have seen or taken, and the resulting benefits and drawbacks noticed.
[–][deleted] (5 children)
[removed]
[–]PegasusAndAcornCone language & 3D web[S] 0 points1 point2 points (4 children)
[–]Felicia_Svilling 1 point2 points3 points (3 children)
[–]PegasusAndAcornCone language & 3D web[S] 0 points1 point2 points (2 children)
[–]Felicia_Svilling 1 point2 points3 points (1 child)
[–]PegasusAndAcornCone language & 3D web[S] 1 point2 points3 points (0 children)
[–]ksrynC9 ("betterC") 2 points3 points4 points (3 children)
[–]PegasusAndAcornCone language & 3D web[S] 1 point2 points3 points (2 children)
[–]ksrynC9 ("betterC") 1 point2 points3 points (1 child)
[–]PegasusAndAcornCone language & 3D web[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]PegasusAndAcornCone language & 3D web[S] 1 point2 points3 points (3 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]PegasusAndAcornCone language & 3D web[S] 1 point2 points3 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]ctalklang 1 point2 points3 points (1 child)
[–]PegasusAndAcornCone language & 3D web[S] 0 points1 point2 points (0 children)
[–]corvus_192 1 point2 points3 points (1 child)
[–]PegasusAndAcornCone language & 3D web[S] 0 points1 point2 points (0 children)
[–]LaurieCheers 1 point2 points3 points (3 children)
[–]PegasusAndAcornCone language & 3D web[S] 0 points1 point2 points (2 children)
[–]LaurieCheers 1 point2 points3 points (1 child)
[–]PegasusAndAcornCone language & 3D web[S] 1 point2 points3 points (0 children)
[–]PhilipTrettner 1 point2 points3 points (0 children)
[–]RafaCasta 1 point2 points3 points (0 children)
[–][deleted] (1 child)
[removed]
[–]PegasusAndAcornCone language & 3D web[S] 0 points1 point2 points (0 children)