Chic documentation
Houlder Technologies

Frequently asked questions
Mailing list


Development with Chic

Chic and conventional C++

Hidden Data ("pimpls")




1) Who should use Chic?

Chic targets professional C++ programmers. It is not yet for novice programmers. We recommend that you have at least a year of experience with conventional C++. If you set up Chic yourself you also need some knowledge about your C++ compiler, the operating system you're using, and so on.

2) Under what license is Chic released?

Chic for Linux is free of charge. For details, please read the license.

Development with Chic

3) Can I modify the implementations without affecting the interfaces?

Yes. When you generate compile files from a hic-file you can choose whether to generate all files or only the cc-file. If you choose the latter, it means that the clients of your class will not be affected if you for instance change a function body or variable initializer.

4) Can I design interfaces separately from implementations?

Yes. You can design the interfaces and give the functions empty bodies. When you're satisfied with the interfaces you fill in the bodies and only generate the cc-file as explained in the previous question.

5) Is there a preferred way to write C++ when I use Chic?

Chic makes it easier to write good C++. In general, good code is composed of many small functions and classes rather than a few large ones. Small functions are better than large ones because you cannot reuse a part of the internals of a large function. Similarly, small classes lead to more modular code. So the more modular and extensible code you write, the more gain you will get from using Chic.

If you one day need more advanced features such as templates, nested namespaces or nested classes, Chic makes life easier for you. The overhead for writing and maintaining code with these language features can be considerable when writing conventional C++. With Chic, the overhead is almost eliminated. We thus encourage you to explore the modern features of C++ and use them when they will ease you and your team's total programming efforts.

Chic and conventional C++

6) Do I ever have to bother with the compile files?

If you always edit hic-files it's very rare that you will have to look at the compile files. But it can happen that your compiler emits error messages (due to errors in your code) that might require you to look at the files.

You will only have to deal directly with compile files if you write hic-files yourself but only distribute the compile files as discussed in another question.

7) Do I have to convert my conventional C++ code to Chic C++?

No. Chic C++ is intended to be fully integrable with conventional C++, so there is no need to convert legacy code. Quite to the contrary, in general we encourage you to leave legacy code as it is and rather spend your efforts on writing new code with Chic. This way you'll be the most productive.

However, when you have used Chic for some time and you face a major upgrade on some legacy code it's not unlikely that you will feel gloomy about the prospects of having to write conventional C++. Then it's the time to convert the code.

Should you have any problems using Chic alongside conventional C++, please notify us.

8) Still, I want to convert conventional C++ code, how do I do it?

The main procedure is to make a .hic file, insert the header and substitute the semicolons that end function and variable declarations with function bodies and variable initializers from the implementation file(s). Remove the include directives and declarations that Chic can generate itself. Finally, try generating and modifying the hic-file until you can generate compile files that compile and that are functionally equivalent to the original files. The whole operation seldom takes more than 5-10 minutes for an average file.

Chic will refuse to delete the original files since they have not been generated by Chic, so you should move them to some other directory before generating compile files.

We recommend to convert one module at a time and test the resulting files properly. It's easy to introduce subtle bugs and if you try to convert multiple files at the same time, such a bug can be hard to track. If you don't write unit tests, this might be the time to start.

9) Can I create a hic-file from compile files ("reverse-engineer")?

From version 0.9 Chic comes with a reverse engineering module. The module is only intended as a tool to create a hic-file from C++ files generated by Chic. It is not a general purpose converter from conventional C++ to Chic C++, although it might sometimes be helpful in doing just that.

10) Is there any conventional C++ I can't use with Chic?

In hic-files you should avoid:

Also, there are a few infrequently used C++ constructs that are not yet supported.

In particular, we do not recommend Chic for low level system files as these are generally peppered with macros and compiler specific code.

The C++ language is big and it will take some time before Chic is fully ISO C++ compliant. If you're into the details of C++ you will be able to contrive code that Chic cannot yet handle. Until it can, and if you should need some unusual C++ features that Chic cannot handle, try to put the code in a section or in the worst case resort to conventional C++.

11) Can I use Chic for pure C programming?

In theory, ANSI-88 C is for most practical purposes a subset of C++, so what works for C++ should work for most of C. In practice though, since we've not actively targeted C programming, chances are big that you will run into problems. We suggest you leave C code as it is. Chic should be able to parse it correctly.

Supporting Kernighan and Ritchie C or C99 is not a priority. However, note that old-style function declarations are recognized in header files.

12) I'm the first in my team to use Chic, what do I do?

The best is to start using Chic on a new project on which you have complete ownership of the files. Keep the files physically apart from the rest of the system to minimize the risk that a colleague accidentally modifies a compile file instead of the hic-file. Also, keep the compile files in the same directory as the hic-files.

Another option is to generate the files with the clean files option set. If somebody modifies the compile files, you have to manually correlate them with the hic-files. Typically you use "diff" to compare old and new compile files and update the hic-file with eventual changes. Such an approach is obviously error prone. But if you're for example a contract programmer it lets you write the project with Chic, generate compile files, indent and beautify the files, and finally ship them to the client. The generated code is almost certainly leaner and more consistent than you would write yourself.

Hidden Data ("pimpls")

13) When should I use hidden data?

Classes that are under development, classes that are widely used but may change, base classes and "mix-in" classes in class hierarchies are all good candidates for hidden data. High level classes packed with private data such as GUI components are also ideal to equip with hidden data.

When you get used to hidden data, you might want to use them by default. You can then turn on the hidden data flag for the whole project and turn it off for directories and individual files where you don't want them. That way you can toggle hidden data for the whole project by simply toggling the project flag.

14) When should I NOT use hidden data?

Do not use hidden data for classes that have complex memory management. The assumptions Chic makes on the class layout may be incorrect. Also, please note the restrictions on the classes that can have hidden data.

In general there is little gain in using hidden data for small or stable classes such as containers or, say, a class representing a coordinate even if they're widely used.

15) Why does Chic add a default constructor and a destructor to my class?

If there are no constructors in your class the compiler will generate an inline default constructor. Similarly, if there's no destructor the compiler will implicitly generate an inline destructor. To create any of these the compiler needs to see the full definition of the hidden data class. But as that definition is hidden the compilation would fail. To prevent this Chic adds a default constructor and a destructor if needed.

16) How can I copy a class with hidden data?

Analogously to the default constructor and the destructor discussed above, the compiler may create inline definitions of the copy constructor and the assignment operator. While generating these, the compiler needs to see the full definition of the hidden data class. Not having access to this definition, the compilation fails. To copy a class with a hidden data you must therefore yourself add a copy constructor, an assignment operator, or both to your class.

17) Why does my compiler complain that SomeClass_Implementation is undefined?

You are most likely trying to copy construct or assign an instance of SomeClass to another and SomeClass does not have an explicit copy constructor or assignment operator. See the question above.

18) Why doesn't Chic add a copy constructor and an assignment operator to my class?

A C++ compiler generates a copy constructor and an assignment operator only if they're actually called. It's legal and common to have a class that cannot be copy constructed or assigned as long as you don't try to perform any of these operations. As Chic cannot know whether or not you're going to copy construct or assign your class, it takes a conservative approach and assumes you will not do either.

19) How do I write a copy constructor and an assignment operator?

Here's an example to get you started. Chic will correctly make hidden data for this class.

class MyClass : public MyBase

  MyClass(MyClass const& rhs)
    // First construct base class.
    // Then construct all variables.
    ptr(rhs.ptr.get() ? rhs.ptr->clone() : 0),

  operator=(MyClass const& rhs)
    if (&rhs != this)
      // First assign base class.
      // Then assign all variables.
      ptr.reset(rhs.ptr.get() ? rhs.ptr->clone() : 0);
      var0 = rhs.var0;

    return *this;

  std::auto_ptr<YourClass> ptr;
  int var0;


20) Completion fails with a 'Cannot load library' message?

The completion is in a separate module, not in the Chic main executable. Be sure the dynamic library ( or similar) is present in the Chic distribution binary directory.

21) Why do completion results alter while I'm editing a file?

The context of the completion is in part determined by the last successful update of the file. If you have considerably modified the file since you last updated or generated compile files from it, Chic might fail in guessing the right context of the completion. The remedy is simply to update the current buffer (e.g. in XEmacs type: M-xchic-update-current-buffer). Especially when you begin to edit a new file the context will change rapidly and you should take care to update or generate regularly.


22) Will Chic be ported to/be compatible with XXX?

With the first release of Chic we're only targeting Linux with X/Emacs and Vim. Versions for other operating systems and more clients are planned after this. If you wish, you're of course welcome to write a client for your favorite editor/IDE. Have a look at the provided clients, it shouldn't be too difficult if you know your editor/IDE well.

23) When will Chic support feature XXX?

What's lacking to support the entire C++ language and effectively do away with include directives and forward declarations will not be added in the first release. We consider it more important to make the environment stable and easy to use.