Advantages / Disadvantages of Header Files

What are the advantages and disadvantages of using header files in C or C ++, for example, in Java? I think classes should be designed from the outside, so it’s nice to have header files and don’t have to go through implementation details. However, again, each function declaration is duplicated in two files. If C and C ++ were invented today, would they use header files? Is this mechanism outdated or necessary?

+5
source share
3 answers

Taken from a related blog post by Eric Lippert, who says very well:

I would ask an equivalent question, why does C ++ need header files? Header files seem to be a huge potential point of failure; all the time I edit C ++ code and change the method signature; if I forget to update the header file, then the code does not compile and often gives some critical error message. Hope this great value actually buys you something.

He buys the compiler of one thing, and the user one thing.

, , "cpp" "obj" , , . , cpp . cpp, , , .

, " ". , , , obj, , - .

, # ( ) Java, .

+12

- . . Java javadoc. Java IDE API, . , . C , .

+1

, C ++ .

Java , -, . ; , .

-2
source

All Articles