[SUGGESTION] Namespace definition to use += instead of =
#634
Replies: 13 comments
-
|
By supporting nested namespace definition, the distinction from other declarations raises. Originally posted by @JohelEGP in #273 (comment)
Variables can be assigned to, yes. Shadowing does redefine what the identifier means for the current scope.
I disagree. |
Beta Was this translation helpful? Give feedback.
-
Maybe the last "and doesn't shadow" is wrong. |
Beta Was this translation helpful? Give feedback.
-
|
I like your idea,
Because shadowing happens on declarations, so |
Beta Was this translation helpful? Give feedback.
-
If Cpp2 would support extension methods, it would be another use case for t: type = {}
t: type += {
// Extension method
f: () = {}
} |
Beta Was this translation helpful? Give feedback.
-
|
In cpp, the syntax for defining and reopening a namespace is same. We can do the same in cpp2. |
Beta Was this translation helpful? Give feedback.
-
|
@AbhinavK00 Yes, that's true, and Johel is suggesting that this "same syntax" for namespaces be |
Beta Was this translation helpful? Give feedback.
-
|
Ah ok, so here's what I think. |
Beta Was this translation helpful? Give feedback.
-
|
It's already context free.
|
Beta Was this translation helpful? Give feedback.
-
I'm not talking about cpp2 has a whole. Someone on reddit recommended the following syntax for aliases and Herb pointed that this won't be context free as the compiler would have to look up whether "something" is a class, namespace or else. The current syntax is context free as you specify upfront what you're aliasing to. |
Beta Was this translation helpful? Give feedback.
-
|
https://github.com/hsutter/cppfront/wiki/Design-note:-Namespaces says namespaces could become partial classes. |
Beta Was this translation helpful? Give feedback.
-
|
Yes. That's what this from the OP was alluding to:
|
Beta Was this translation helpful? Give feedback.
-
|
@AbhinavK00, Good point 👍. Consistency is an important factor to consider in |
Beta Was this translation helpful? Give feedback.
-
|
Yes, namespaces and partial classes could both be reopened, so But for now namespaces are their own thing. Still, I think it's consistent to let |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
A wild thought.
Maybe a namespace declaration should use
+=instead of=.So
ns: namespace = {would becomens: namespace += {.+=denotes in-place addition, not definition.But notice how
:remains despite+=.So it both (re)defines the namespace's identifier, which is valid, and adds to it.
Then all remaining uses of
: /*signature*/ =would denote definition of the non re-definable kind, which is a bigger plus.How does that fit with the current Cpp2?
What about with your idea to replace
namespacewith a metafunction, @hsutter?Originally posted by @JohelEGP in #273 (comment)
Beta Was this translation helpful? Give feedback.
All reactions