954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

why doesnt c# require header files?

i wonder it, because i hate c++ header files. if c# compiler has a way of getting rid of them, why cant c++ do?
here some similar info but i am not satisfied.
http://stackoverflow.com/questions/1305947/why-does-c-need-a-separate-header-file

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 
i wonder it, because i hate c++ header files. if c# compiler has a way of getting rid of them, why cant c++ do? here some similar info but i am not satisfied. http://stackoverflow.com/questions/1305947/why-does-c-need-a-separate-header-file

This is a C/CPP forum question disguised as a C# question--flag as bad post! :P

DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

No i posted it to here to have Scott involved in the conversation.
Today he is in good mood. And also i really wonder how c# deals without having header files, if that can be done, why c++ has them, of course it cant be for bothering the programmer.

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

Some 20 years ago I programmed in this language
It had the concept of a DEFINITION MODULE(= +-header file) and IMPLEMENTATION MODULE. You could design all your definitions and then let a team of programmers fill in the implementations. It would complile even if not all implementations were filled in.
So you could say FROM Circle IMPORT Draw; to use the Draw procedure, while other procedures like CalculateArea are perhaps not yet implemented!
In C (I believe also in C++) when you include a header file, all of the implementation would be loaded in your program, even if you don't need it. Possible that a smart C or C++ compiler will prune out the code that is not needed afterwards, I dont know.
C# is a modern language and VS is a nice environment to develop in, so who needs headers in the 21th century?

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

So you think c# is better than c++? if Narue were alive, she would prove you wrong as a well known c++ geek :)

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

Did I say anywhere C# was better?
Better in computer languages does not exist, for instance I find this language not bad;)

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 
No i posted it to here to have Scott involved in the conversation. Today he is in good mood. And also i really wonder how c# deals without having header files, if that can be done, why c++ has them, of course it cant be for bothering the programmer.


When am I not in a good mood!?

Danny -- To the point you made that is also available in C# it is just done a little differently. You can create an assembly full of interfaces (unimplemented methods, just like the header file) and give the assembly to your developers. They can each start implementing their respective methods. I couldn't image developing something like this to be honest. You'll usually miss something along the way. It seems so much easier to just shoot a few emails back and forth and establish the "middle ground" where your code meets up and goes from there. If you forget an interface then you have to go back in and add it, rebuild your assembly, distribute it to the team, hope everyone upgrades and you don't have two different versions of the interface floating around with different signatures, etc. How did this work for you?

Serkan -- I don't know that much about c/cpp to be honest. I 'grew up' on pascal and switched over to pascal with some other archaic languages along the way. I think the thread you posted gives some very good examples:1.To improve build times.
2.To link against code without having the source for the definitions.
3.To avoid marking everything "inline".
Beyond that .. I don't know :(

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 
Did I say anywhere C# was better? Better in computer languages does not exist, for instance I find this language not bad;)

I was about to say something practical, then I read your link and lost it--:D

DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 
Did I say anywhere C# was better? Better in computer languages does not exist, for instance I find this language not bad;)


I still write programs on my TI-85 during class sometimes :)

[edit]
"" what DdoubleD said. I read the link after I posted
[/edit]

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

@Scott No problem whatsoever. We where three guys sitting in a room with 3 computers. We talked to each other. I believe e-mail as we know it now had to be invented...

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

As less of a discussion answer, and more of a poke at a simple explanation.

header files are a type of include. so when you need some functionality in your program you don't have to start from scratch. Some code is available to start with, and when you program is compiled this is compiled into your application. So it has no prerequisites.

in C# you do the same thing. except you only reference the code that is already available, that code is the .net framework.

my opinion is C++ is better because it makes more portable applications, but C# is my favorite language because its very powerful yet easy to learn and understand.

in C# you want to write a line to console you use the console class of the System library. System.Console.Writeline("blah"); the system library is part of the .net frame work and is installed on the client computer prior to your application.

in C++ if you want to write a line to console you first include the header ostream, then you pass to the output variable the "cout" the text you want to show on the console, cout<<"blah"<< endl; . when the program is compiled, a copy of the ostream code is included in the executable needing no preexisting library.

So its practically the same thing, just if C++ looses its headers, then it will just be unmanaged C#... and who wants that? not me.

Diamonddrake
Master Poster
724 posts since Mar 2008
Reputation Points: 442
Solved Threads: 89
 

Text from Wiki -

A header file commonly contains forward declarations of classes, subroutines, variables, and other identifiers. Programmers who wish to declare standardized identifiers in more than one source file can place such identifiers in a single header file, which other code can then include whenever the header contents are required.

The C standard library and C++ standard library traditionally declare their standard functions in header files.

Newer compiled languages (such as Java, C#) do not use forward declarations; identifiers are recognized automatically from source files and read directly from dynamic library symbols. This means header files are not needed.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

i find this thread so informative. keep posting guys, this is a very useful and enlightening discussion. thanks for your answers.

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

i created a thread in geeks lounge "what do you think would be milestone web-social-application?", i would like to hear your opinions about that thread. Thanks in advance.

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You