aboutsummaryrefslogtreecommitdiffhomepage
path: root/notes/namespaces.txt
blob: 161d0cb1f49ac2e827c59764ba49e9e0207ee352 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

Namespaces or not?
==================

Problems with NOT having namespaces:
* You can't directly see in which module an identifier is defined.
* Name conflicts between modules

Problems with namespaces:
* Conflicting names are often handled in an inconvenient way.
  In Java, it is inconvenient to use e.g. java.util.Date and 
  java.sql.Date at the same time, because one will have to be
  specified by the fully qualified name.
* In most languages EXCEPT e.g. Rust, module names itself can conflict.


Solutions to "You can't directly see..."
----------------------------------------

* Enforce prefixes in identifier names. E.g. "SthType1" and "sth_func2"
  for a module called "something".
* Use namespaces, e.g. "something:Type1", "something:func2"

Solutions to "Name conflicts between modules"
---------------------------------------------

* Allow prefix renames at import. E.g. Sth/sth to Someth/someth
* Allow prefix additions at import.
    - perhaps use a special character/syntax?
    - example:
        \depends something 1.0 as %sth
        \depends something 1.0 as sth
        ...
        %sth.Thing t = ...
        :sth:Thing t = ...
        |sth|Thing t = ...
        ::sth::Thing t = ...
        sth::Thing t = ...      (probably easiest to implement)
        sth:Thing t = ...       (might conflict with goto)
* Use import-defined namespaces.
* Require a namespace for ambiguious identifiers.

Two-level module system
-----------------------

The repository name could be included in the module name.
See modules_names.txt. The syntax might looks like this:

    \depends std:string 1.0
    \depends mainrepo:avl_tree 1.0
    # example with full URL (last : is the delimiter)
    \depends https://git.example.com/theuser/btree:btree 1.0

What delimiter to use?
These look good in simple names:
    :
This work well in URLs, but NOT in .slul files
    #
These could work in URLs:
    ?   space
Flipping the namespace/name around, e.g. "avl_tree@mainrepo" is also an
option, but I think it gets harder to read (EXCEPT for long URLs, where
it is IMO more readable).

Spaces:

    \depends std string 1.0
    \depends mainrepo avl_tree 1.0
    \depends https://git.example.com/theuser/btree btree 1.0

Reversed order:

    \depends string@std 1.0
    \depends avl_tree@main_repo 1.0
    \depends btree@https://git.example.com/theuser/btree 1.0

Named repo specifications:

    \depends std:string 1.0
    \depends mainrepo:avl_tree 1.0
    \depends theuser:btree 1.0
    \depends b:unmaintainedthing 1.0
    \ext_dep_repo theuser https://git.example.com/theuser/{MODULE}
    # bundled/vendored repo
    \bundled_repo b bundled/

Two-level module system and slul-interfaces
-------------------------------------------

With a two-level module system, slul-interfaces would have to be
two-level as well.

It would have to handle:
* Standard repos, e.g. "std" and "mainrepo"
* User repos, e.g. URLs

The former could use their names verbatim.
The latter would have to use some kind of hash.