dyatkovskiy's blog

By dyatkovskiy, history, 5 years ago, In English

Hi folks!

I think most of you are cool programmers and know several programming languages. Below are some thoughts (and one open-source project) regarding to C++.

Disclaimber

(below is not some super cool algorithm, neither problem solution, rather thoughts, and some may be off-topic proposal, so sorry for that)

Stake

I love the performance you can get by means of C++. If you know what are you doing, you can get awesome results. But syntax... well, I'd like to make it better.

At least following things:

  • modularity
  • reflection
  • set of syntactic sugars. Currently I'm working on modularity. Yep, there are several versions of modules TS. But main thing I disagree with modules TS and like is that it introduces one more degree of namespace notion. First degree is a file system, second are C++ namespaces, and it is proposed to have a third degree which is modules namespace. So, when you're developing complex project you should make similar decision three times: where to put file?, in which namespace it should be?, in which module it should be? This is not about discussion, though. It's OK. Everybody can follow his own way. May be some people love this.

Anyways let's consider another approach. Instead why not to keep single namespace notion all the way? That means coincidence of filesystem path and legacy C++ namespaces. One may say this sort of restriction is too much for C++, for it was always about good flexibility. I think that may be it reduces a flexibility a bit, but it will simplify packages lookup routine. It will also unload your brains with eternal question "in which directory should I store that thing?" Basically, I follow approach "good laws are limitations of our worst to release our best". And you know, what is the reason of having a tool if it is too liquid to be held in your hands? There should be some border between flexibility and liquidity after all.

So finally we are about meaty part of this post. In first part of C++ improvements I propose next modules concept. Just look at that.

// File1.cpp
#import com::mylib::MyAnotherClass;
#import com::guyslib::ThirdClass;
package namespace com::mylib {
  class MyClass {
    MyAnotherClass v;
    guyslib::ThirdClass v2;
  };
}

or even this (second option):

// File1.cpp
package namespace com::mylib {
  class MyClass {
    global::com::mylib::MyAnotherClass v;
    global::com::guyslib::ThirdClass v2;
  };
}

In first case we do manual import. In second option we use "global" keyword and it triggers automatic import mechs. There are no additional degree of namespaces. We reuse existing namespace concept with a single new attribute "package".

"package" attribute tells compiler that current file is a... package! Well, it also tells that it is allowed to define only symbols with same name inside. Anywere else you can treat it just like a regular namespaces.

Also package namespaces are allowed only for files with particular path which should correspond to namespace path. All this sort of measures makes it really easy to perform fast dependency lookup and resolution.

Second option with automatic dependencies lookup is implemented already. It is based on clang frontend and "dependent types" mechanics. Well, when I started work on it, that was like a challenge to make it automatic. As it was later discovered, though, it is not always convenient in practise.

The reason why I started this thread is that perhaps some of you guys kind of on the same wave and perhaps want to participate.

If you guys interested in compilers development, or just want to make this world a bit better as I do...

below is a link to my open-source clang-based project. https://gitlab.com/dyatkovskiy/cppl

Currently I'm about to implement #import directive (manual dependencies declaration). And if some of you are interested, please feel free to email me, or join the project.

And thanks for your attention!

  • Vote: I like it
  • +25
  • Vote: I do not like it