Robin Rodricks
Robin Rodricks

Reputation: 113956

Why cannot modern C++ IDEs auto-generate header files?

I understand the benefits and flexibility that header files provide, symbol discovery, the speed-up of processing for the compiler, etc. What I don't understand is why modern C++ IDE's don't auto-generate header files based on the members/methods added into the code file, thus reducing the manual labour involved in keeping the header up-to-date with the code file, and vice-versa. Since the IDE only makes incremental changes to the header file, developers may modify the header and changes are preserved.

Refactoring could be provided for adding/renaming/removing method arguments, for renaming methods, for moving methods into another class, and so on. During such refactoring the IDE would take care of updating the header + source files.

The functionality could be similar to the Visual Form Designer in Visual Studio. When you design a form, the IDE auto-generates code for the same, which is stored in a separate, IDE-managed source file. Devs may also modify such code files, or may include additional code in the user-managed source file.

Working with professional C++ source code, I've encountered all kinds of dubious practices :

Although I am not a professional C++ programmer, coming from a high-level background (JS, C#, AS3), I can feel the "downgrade" working with C++ first-hand and I don't see why some of these disadvantages cannot be eliminated by the IDE itself.

By no means am I mocking the IDE or the compiler in any way. I understand C++ allows for more complex methods of defining a program than modern-day languages do (eg. C#), and though the complexities of templating elude me, I'd like to see some of the benefits of higher level languages brought into C++ application development.

Upvotes: 23

Views: 7247

Answers (1)

NicholasM
NicholasM

Reputation: 4673

The premise of your question, I believe, is not correct.

The Eclipse Luna IDE can auto-generate implementation stubs (in a CPP file) after you define a function (or class member function) in a header file.

You type the following in the header:

class MyClass 
{
  void my_method(const OtherClass& o, const std::string& name) const;
};

Then click "Source > Implement Method". Eclipse correctly generates something like this in a CPP file:

void MyClass::my_method(const OtherClass& o, const std::string& name) const
{
   // TODO: Auto-generated method stub.
}

I think this is a more typical use case than "[adding] members/methods... into the code file" and then "auto-generat[ing] header files". The idea is that most developers will design (create) an interface, and then develop an implementation (sometimes in a CPP file).

As for "Useful functions defined in the header file", this is common practice where developers want their functions to be inlined by the compiler in many translation units.

Upvotes: 1

Related Questions