• Advertisement
Sign in to follow this  

Tendency to omit source file

This topic is 3005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement