Nice that you like it!
Now about your remarks/question:
attributesThe syntax for type definitions is: 'type <name> <definition> <aliases>'.
This works quite well for some types, but might indeed look weird on enum and structs that
use {} in their definition. Since function definitions look similar to struct type definitions and
they use the syntax: 'func <return type> <name> (<params>) <attributes> { .. }', it might
be an idea to make struct/enum refs similar to functions so that it becomes:
type Point struct @(packed) {
int32 x;
int32 y;
}
What do you think?
semicolonIn regard to the remark about missing semi-colon after a '}', the rule is very simple: In C2 a '}' will
never be followed
by a semi-colon. This is done because C sometimes requires it and sometimes not. It's also easier on the eyes.
orderingFunny that you find ordering helpful. I just jump-to-definition in my editor and don't care much about where something is
defined. The design rule here is '
define everything once'. This is one of the foundations of C2. So no forward declarations,
so then you need a multi-pass parser since declarations cannot mutually refer to the other.
importsOne other design goal is to keep the syntax as simple/readable as possible since you spent a lot more time reading code than
writing it. So in my opinion, all the extra public {} is just plain ugly and unnecessary complex. Also it's important to think about
the semantics of such a thing. That is, what does it
mean. That should also be very clear. Since C2 does no symbol mangling
like for example C++, some restrictions apply (for example no operator overloading on functions, etc).
So currently there are 2 access types:
- public - this means visible outside module (if imported)
- non-public - only usable from within same module.
The concept of a third one has been discussed earlier, namely a 'private' access, so only usable within the same file.
After consideration this was deemed to introduce nothing new and only make things more complex. Also consider the
no-mangling rule.
auto / lambdaBoth the auto and lambda concepts have their place, but they simply don't fit into a c-like language. I
find the
auto keyword annoying, since I cannot see the type directly. And the 'gain' is nothing much.
Lambda functions are very nice, but required functions as first class citizens to make them truly useful. This
just doesn't work in a C-like language. So keep it mind that C2 tries to improve C while keeping the same 'core'.
struct functionsYou have a point about the syntax of struct functions. There might be a better syntax. The thing to keep in
mind is the no-name-mangling though. Also (quote) C2 is not C++ (unquote). So there is no viable and this
pointer in the sense of C++. Struct functions are purely syntactic sugar (but very nice nonetheless).
I am toying with the idea of adding the struct members in the namespace of a struct functions to avoid all
the 'this.' usage. I cannot see any real objections so far and the code does look a lot cleaner (and the same
as for example C++).
stdlib/stdio importsWhen code in some file wants to use symbols from another module, it needs to import those. The 'import verylongname as van'
allows developers to make their own code look much nice, while allowing longer module names to be used. Imports are NOT
handled in the same way is C/C++ #include's. Those are much more expensive. In a C2 program, the stdio code is only parsed
once for the entire compilation of the entire program, not once per file. Also the symbol table is linked into the global symbol table,
a very cheap operation. If you worry about speed, you should definitely switch to C2
On my laptop C2 compiler parses around 1.5-1.8 million lines of C2 per second in a single thread!
Whow that was also a long reply. Your ideas were definitely useful. So we need to re-evaluate the syntax of struct-functions and
the syntax(position) of attributes for enum/struct types.
--Cheers--