There was quite some interest in C2 at Fosdem'13 and I had some great
discussions afterwards. So that was very nice. Additionally there were
some great Ada presentations, which got me thinking as well.
This post is a RFC (request for comments) about the C2 package system. I
have some ideas and would like your feedback.
In brief, the current package design is:
- every file is in a package.
- multiple files can belong to the same package.
- when using symbols (functions/types/vars) from other packages, the packages
has to be 'used' like:
'use utils;'
- when using symbols from other packages, you only need to specify the package
prefix if there are conflicts (A::Type and B::Type), otherwise you can just
use Type.
- the package operator is '::'
- you can only use public types as return/argument type for functions.
The ideas i'm toying with are:
A. replace the '::' with '.', so package::symbol becomes package.symbol.
The advantage would be better readability, but it would blur the distinction
between struct.member and package.symbol.
B. The 2nd idea is to always require the full naming (so package::symbol)
for external symbols. The disadvantage of this is more typing, while the
advantage would be that adding a symbol to an external package will never
break the using code. For example: if you have package T that uses packages
A and B and there is a type A.Type, adding B.Type will break T.
C. Adding an optional 'as Y' option to use statements. So
use my_long_package as mlp;
This can partly negate the disadvantages for point B.
D. Each package symbol can be public or not. I'm thinking about adding a third
option, just for type: 'opaque'. Opaque types may be used as (return/argument)
types in public functions, but the clients can only use them to pass around
(not derefence/use them). Clients would be able to allocate them on the stack,
since sizeof() could be used on opaque types.
The advantage of this keyword is that it makes the opaque-pointer pattern
explicit. Also clients would only need a recompile if the sizeof() changes
effectively.
So I'm interested in your opinions about:
Q: (A) what would be a better package operator? :: or . ?
Q: (B) require full specification of external symbols? (is this worth it/how
big would the problem really be?/add -lax-naming option?)
Q: (C) What do you think about use <long> as <short>?
Q: (D) Any other options?
Q: any other ideas?
NOTE: I had to disable forum registration for SPAM reasons, but I'd be happy
to create an account for anymore. Just mail me your email/login-name.
Cheers,
Bas