-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please introduce namespaces in the language #4250
Comments
C# has a cross-file global namespace that all declarations belong to. The closest thing would probably be: Libraries can declare namespaces as top level members, and as members of other namespaces. namespace someIdentifier {
// declarations
} Other existing top-level declarations can also be declared inside I namespace, including imports and exports. The namespaces (unless named with a library private name) are exported names, part of the export scope of the library. They are names in a scope just like any other name, and mustn't conflict with a non-namespace name. If two namespaces with the same name are introduced as members of the same namespace, by importing or using, any name they both introduce is conflicted, just like conflicted imported names today - it's only an error of code refers to that name. Prefixed imports, namespace prefix {
import "...";
} except that the The In short: I see zero chance of making Dart scopes be "independent of the file system". Libraries are units of import, and exports, and libraries are identified by a single file. Having a solution file that defines the files of the program, and files themselves not needing to have imports, is a content different direction, and not one I expect Dart to take without it providing a significant benefit. What namespaces can do is to stratify the names exported by a library into a hierarchical structure, which can allow multiple declarations with the same name, as long as they are in different namespaces. |
Adding the concept of namespaces (like they exist in C#) would ensure a abstraction layer to the code and would help to decouple file system structure from logical code structure. Given that, the code would be independent of the folder structure which would help portability.
Having namespaces implemented would also greatly reduce the complexity and burder of managing the import / export statements that also occurs and forms a bottleneck in Python.
Given namespaces (above and beyond other advantages) a Flutter project could then potentially have a project or solution file (see Visual Studio projects) and then imports / exports could focues on namespaces instead of folder structures.
Please don't throw this idea away. For such a great a modern language like dart this would be a highly desirable productivity feature.
The text was updated successfully, but these errors were encountered: