Tendency to omit source file
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
"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.
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.
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.
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 RavuyaBack when I last touched pascal, you used it just like C without headers - extern declarations and link...
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.
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.
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
Popular Topics
Advertisement