Rakesh's Blog

#include

Say I have the following code in

 

Employee.h

 

namespace Company

{

     class Employee {};

}

 

 

Manager.h

 

namespace Company

{

     class Manager {};

}

 

When the user drags an inheritance line between Manager and Employee, we will generate the following code in Manager.h

 

Manager.h

 

namespace Company

{    

     class Manager : Company::Employee {};

}

 

Your feedback on the following issues will be appreciated.

 

  1. Note that we didn’t generate the “#include Employee.h” in Manager.h file. Would it be reasonable to assume that the user will have to deal with inserting proper include statements in the Manager.h file?

 

The following are some of the reasons that deter us from doing it ourselves

·        Redundant #includes may introduce clutter, may cause compilation errors

·        It will be difficult to find the correct path to Employee.h

·        What if the user #includes everything in a precompiled header

·        What if the #included header requires other #includes before it?  Many headers do not embed #includes for dependent headers, instead relying on the .cpp to #include the dependent headers separately. We cannot figure out what is ‘right’ without a proper dependency graph.

·        Yes what we generated won’t compile but at least we just did what the user requested. It is in a better state, than actually generating something more than what the user requested and that causing more compilation errors.

 

  1. Would you prefer that we generate “Company::Employee” or just “Employee” as the base name? If we do the short name the generated code will be…

 

namespace Company

{

     class Manager : Employee {};

}

 

 

Published Thursday, September 16, 2004 6:07 PM by rakeshna

Comments

 

Colin said:

#1: I'd expect the #include to be inserted automatically and I think the code would be more likely to compile correctly with the #include than without it.

#2: I'd expect the class name to be unqualified if the classes were in the same namespace and qualified if the classes were in different namespaces.
September 16, 2004 7:05 PM
 

Jake Good said:


My $.02

#1 I think it's ok to leave it out, when you're writing code you don't want to be completely nieve to the fact that generated code can contain mistakes. Plus this almost works like writing your test cases first. Your Manager class is expecting to know what Employee is, so when it fails, it causes you to think about how it has to know... rather than just relying on the fact, taking it for granted.

#2 I agree with Colin. It can be smart enough to figure it out on its own. That's one thing that I don't necessarily like about creating interfaces within Visual Studio, if you have long namespaces and somewhat long class names, like Neighborhood. Then your code seems clobbered by namespaces that aren't necessary.
September 17, 2004 6:07 AM
 

David V said:

#1 It seems like it should be an option some where; something I could check to have it auto #include. As for the redundant #includes it would be pretty trivial to do a quick search to see it the same statement is already included.

September 17, 2004 7:59 AM
 

Dan said:

I would expect the include, but I would not want the namespace as it is redundant.
September 17, 2004 10:07 AM
 

lowercase josh said:

There is a philosophy that header files should be self-contained. That is, if I need the Manager class in one source file, I shouldn't have to know that it's derived from Employee and ensure that header is also included. So Manager.h should, somehow, make sure that Employee.h gets included if it needs to be.

IMO that's a lot nicer than having to hunt down every header file you need to make things compile. Errors from multiple #includes are trivial to avoid, and a small amount of noise at the top of the file won't kill anyone. Also, that's what the old Class Wizard does (I think... isn't it?), so I don't think it would surprise people.

An option would by nice though, in case somebody's doing a monster include-everything precompiled-header-loving file.
September 17, 2004 10:21 AM
 

Rakesh Namineni said:

Thanks for the feeback.
Since most of you wanted the #include statement generated, we have decided to do that in C++ Class Designer Visual Studio 2005 release.
But we will not provide any option that would turn it off.
And we will not generate fully qualified base name, only if the derving types' namespace is different from the base types' namespace name.
Again thanks for the feedback.
September 21, 2004 4:25 PM
 

Malagudi Chittappa said:

I think these are very wise decisions that you have made. I would like to see more people in Microsoft listen to customers more often ....
September 27, 2004 4:03 PM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker