Skip to content

zipsegv.net

The value of writing headers

Created 3/28/2026, 6:03:33 AM

A common complaint I hear about C goes something like:

It's so annoying that C forces you to write your declaration twice; once in the header, and once in the implmentation.

I don't exactly disagree with this complaint. I do constantly find myself copypasting declarations from my headers to my implementation files and that is definitely mildly annoying.

However, I don't think there's absolutely zero value in having a separate header file. Having to write the header separately makes me think more about my API and what functions I actually want, or which functions would be convenient to use, rather than which functions would be easy to write.

Of course, it's not like you can't do this with other languages. You could just write the signature of all your functions before writing the implementation, and that would practically achieve the same thing. But honestly, I don't do this in other languages because it's not very convenient (and the LSP will yell at me that my functions don't have an implementation). C forces me to.

Another thing this allows, however, is that it separates the API from the implementation; you can go look at a header and just see the entire API. This role seems to have been taken up by the documentation generator in modern times, which is, fine I guess. If anything, it's probably more readable that way.

Anyway, I do personally prefer languages that don't require headers, but I don't think there's absolutely zero value in having them.

As a sidenote, I do know of one language that lets you (optionally) write headers if you want, and that's D. The D language has interface files which basically perform the same role as header files in C or C++ (although are a little more sane). I have literally never seen these in use in practice, however. Maybe proprietary software authors use them, although I don't know of any proprietary libraries written for D.


Groups: Blog, Writings