Tendency to omit source file

Started by
5 comments, last by Sneftel 14 years, 4 months ago
I heard that Microsoft is promoting a new programming style for C# and managed codes: put all the codes into the header file, so there is no need for source file any more. Is it true? What is the benefit? Thanks. Johnson
Advertisement
"source" and "header" files are C-ism (also used in C++). They exist to get around the limitations of the C compilation model -- in fact, the C preprocessor smashes them all together before the compiler ever sees them, so in fact the compiler is still compiling a single file.

Other languages, including C#, but also including Python, Ruby -- in fact, just about everything that is not directly C-based -- do not have the notion of header/source files. This is not some decisions Microsoft has made, it simply exists because those languages have compilation models that are not as antiquated as C's.
Quote:I heard that Microsoft is promoting a new programming style for C# and managed codes: put all the codes into the header file, so there is no need for source file any more.
Hmm? C# has never had a header/source separation. Neither has Java, for that matter. Or LISP. Header/source separation is rarer than you think.
Quote:What is the benefit?
Turn it around. What is the benefit of header/source separation in C++? Not separation between interface and implementation -- implementation bleeds all over your header files, in the form of private variable and function declarations. And not to make compilation efficient -- compiler design moved past that need, decades ago. Rather, the header/source separation is a side effect of how early linkers were written, thirty years ago, and kept around because they never wanted to break compatibility.
Good points! I agree that it is not necessary to divide into header and source file.
Come to think of it, I don't think I've ever used a language outside of the "C family" that used header files.

I'm pretty sure most implementations of Pascal don't need it, but I'm not sure how they link across multiple files as I haven't used Pascal since first year CS.

Some other language family must use them. It must be slipping my memory.
Quote:Original post by Ravuya
I'm pretty sure most implementations of Pascal don't need it, but I'm not sure how they link across multiple files as I haven't used Pascal since first year CS.
Back when I last touched pascal, you used it just like C without headers - extern declarations and link...

Along the same lines, header files are mostly an artefact of the preprocessor in C/C++. You can code C perfectly without using header files, but in C++ the inability to extern/forward declare templates breaks this.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Quote:Original post by Ravuya
Some other language family must use them. It must be slipping my memory.

It was quite common to have to declare external references in that era; the thing about the C family was the use of preprocessed inclusions to package them up.

This topic is closed to new replies.

Advertisement