Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm new to programming the C family

Status
Not open for further replies.

gwrestling103

Programmer
Aug 30, 2007
6
US
Hey guys, I have a quick and easy question for you programming masters. What is the difference between all of the C languages, such as, C++Microsoft, C++Unix, C++Borland, C, Visual C++, and C#? What are they all used for? Sorry to sound so dumb on the subject of the C family, but I am trying to figure out what language I should learn. If I missed any other languages in the family, let me know. I have read the Java and Python should be in there to, but I left them out for the one purpose of not sounding too much like a 'newb.'
 
Well they are all used to write programs. Obviously.

C is the most portable, but the oldest and non-object oriented.

C++ is derived from C (which means you can still use all your C code and compile it with a C++ compiler). It's object oriented and it happens to be my favorite.

Java is like an evil C & C++ hybrid, except it doesn't create executable files - it creates platform neutral byte-code which needs a Java interpreter to run and therefore isn't very portable. Although, the good thing is that once you compile the Java program into byte-code, you can run it on any platform that has a Java intetreter without porting and/or recompiling it. It also has a HUGE library of classes that are built right into it.

C# is a Microsoft specific (i.e. Windows) language which is like Java (and is trying to compete with Java). It requires the .NET Runtime library to be installed to be able to run programs compiled with C#.
 
Ook. I have an idea of what object oriented but how exactly is it more useful in a programming sence?
 
OOP leads to a lot less spagetti code than non-OOP languages like C...

It has inheritence & polymorphism which is great for code reuse and extension.

Data & Functions are encapsulated better, and have different levels of access to different parts of the object.
 
So if I learn one C programming language, the others won't be much harder to learn right? The basics are the same only minor differences right?
 
Sorry for double post. So basically, Object Oriented makes the code easier to read and more portable?
 
C++, C# & Java all have very similar syntax (sometimes identical), so learning one will make it very easy to learn another.
C on the other hand is not object oriented, so there's a lot of things that are missing, like classes, inheritance, function overloading...
Object Oriented makes the code easier to read and more portable?
Not necessarily more portable, since there are a lot more systems that have C compilers but not OOP compilers.
I'd say OOP makes code easier to read and easier to maintain & extend.
 
Thank you for the help.

If I learn C first, will it help me learn C++ and Java easier even though Java and C++ are OOP? What I mean is, is it worth while learning C or should I just learn C++ and get all of C's features and OOP all in the same package? Is there anything C can do that C++ can't do and would give me a reason to learn C first?

I am sorry if you have answered these questions but I am trying to understand this material as best as possible before I rush and jump into something. I am very new to programming if you couldn't already tell by the quality of my questions.
 
I think C would probably be harder to learn as a first language since it makes you take the longer road to solve problems. Strings are a perfect example - in C a string is just an array of characters, and you have to make sure you have a big enough array to hold the string you want to put in there; but in C++ (or C# or Java) there is a string object which handles all those little details for you.

You can still create C strings in C++ exactly the same way (by making an array of chars), but there's almost never a good reason to choose char arrays over string objects in C++.

Here's an example:
Code:
/***** Using strings in C. *****/
char* str = malloc( 6 * sizeof(char) );
char* temp = NULL;

if ( str == NULL )
{
   printf( "Error allocating memory!" );
   exit( 1 );
}

strcpy( str, "Hello" );
printf( "%s\n", str );
if ( (temp = realloc( str, 13 * sizeof(char) )) == NULL )
{
   printf( "Error allocating memory!" );
   free( str );
   exit( 1 );
}
str = temp;
strcat( str, " world!" );
printf( "%s\n", str );
free( str );
Code:
// ------ The same thing in C++ ------
string str = "Hello";
cout << str << endl;
str += " world!";
cout << str << endl;

Is there anything C can do that C++ can't do and would give me a reason to learn C first?
No. C++ basically is C, but with extra features.
 
The first step is to learn how to program.

For example, OO is as much a way of thinking about the problem as it is a means of implementing the solution. You can do some OO in C quite easily and you can equally avoid using any OO in a C++ program.

The analogy is learning to drive.
The car you use to learn to drive in is not the same as the one you choose to use on a day to day basis. Nor for example will you stick with the same car your whole life.
Sure you might be a bit shaky for a few minutes moving from a Ferrari to a Hummer, but it will be nothing compared to the initial learning effort.

Once you actually understand HOW to program, that is how to express the problem in some kind of implementation terms (algorithms, data structures etc), then the actual programming task itself is not that hard.

Once you've got one language under your belt, learning the basics of most other languages doesn't take that long until you can start producing something useful. Though obviously it will take longer for you to produce something which is elegant.
There are after all only so many ways you can write a for loop for example. Once you know you need one (that's the HOW bit), the rest is simple book work to look up the syntax in the new language.

To switch analogies, a programmer who only knows one language is like a carpenter who only knows how to use a hammer.



--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top