Skip to content

proposal: add namespace keyword #241

@arjendevos

Description

@arjendevos

I am trying to create some packages with Nature, so I will be creating issues/proposals as I go that would make Nature way better.

One thing that bothers me is the namespace. I understand the concept of having a per-file namespace however I don't think this is something you really want when coding. I have four proposals:

Proposal 1: support a namespace keyword alongside the current logic

This would mean that we can add a namespace my.namespace to files in a directory and all those files will be part of the my.namespace namespace. So importing would look like:

import my.namespace

namespace.my_function() // in namespace/file_1.n
namespace.another_function() // in namespace/file_2.n
```n

In this case, you import first to the directory, and then the namespace. Like this:
```n
// my/custom/namespace/random_directory_name
//  - file_1.n -> namespace hello
//  - file_2.n -> namespace hello

import my.custom.namespace.hello

Proposal 2: require a namespace keyword

This would mean every file needs a namespace keyword at the top (like golang) and would remove file-based namespaces. For implementation and consistency sake I heavily support this proposal. The syntax is the same, every file now gets a namespace <your_name_space> keyword at the top of the file.

Proposal 3: add an export keyword

This would mean that we can export certain files in main.n like typescript/javascript does. Example:

In this case, you import first to the directory, and then the namespace. Like this:
```n
// my/custom/namespace/random_directory_name
//  - file_1.n 
//  - file_2.n
//  - main.n -> 
//     export 'file_1.n'
//.    export 'file_2.n'

import my.custom.namespace.random_directory_name
random_directory_name.function_from_file_1()

Edit:

Proposal 4: make directories automatic namespaces

So instead of having a namespace keyword, an entire directory is a namespace automatically. This requires the least amount of changes (in the syntax) and would have huge benefits.

Final thoughts

We need at least one of these proposals otherwise Developer Experience really suffers. In my opinion does 3 not belong in the Nature syntax because everything is public by default, which would make it weird to add an explicit export keyword. So my preference goes to 2 or 4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions