C or C++

C or C++

Post by STUDIOny on Mon Feb 16, 2009 7:04 pm
([msg=18053]see C or C++[/msg])

Just a question, What is the point learning C, when C++ is basically just C, but better?
Also, about C#, its slightly different from C/C++ yes? In what ways?

Cheers.
STUDIOny
Experienced User
Experienced User
 
Posts: 73
Joined: Thu Feb 05, 2009 7:40 pm
Location: Newtownards, Northern Ireland
Blog: View Blog (0)


Re: C or C++

Post by GuGaBoY on Mon Feb 16, 2009 8:23 pm
([msg=18059]see Re: C or C++[/msg])

C++ includes OOP (object oriented programming) support and if you don't use it, it's almost like C - though I've heard that standar I/O functions in C++ are better than those in C.
I don't use C# because I relate it to M$: http://en.wikipedia.org/wiki/C_Sharp_(programming_language)
For more info on OOP:
http://en.wikipedia.org/wiki/Object-oriented_programming
"Imagination is more important than knowledge..." Albert Einstein
User avatar
GuGaBoY
New User
New User
 
Posts: 15
Joined: Fri Apr 25, 2008 5:11 pm
Location: localhost
Blog: View Blog (0)


Re: C or C++

Post by BhaaL on Tue Feb 17, 2009 1:24 pm
([msg=18109]see Re: C or C++[/msg])

Association of C# with M$ is most likely due to the bounds to the Microsoft .NET Framework.
But this does not mean M$ invented C# or owns it of some sort. The major implementations of C# are from Microsoft (based on the .NET Framework/CIL Infrastructure) and from the Mono Project (on Mono, an Open-Source implementation of the CIL Infrastructure/ECMA-335 with some backing of Novell). I do not know any other C# compilers other than those, but it does not necessarily always mean "it's M$!".

C# is a pure Object-oriented language, and could be compared to Java of some sort (Java is compiled to bytecode and interpreted in the JavaVM), with the minor difference that interpretation/compilation are slightly different (Just-in-time compilation to native code vs. VM). Both abstract the low-level things away and let you take care of what matters: the "what" of your code, and not the "how".
C is more or less purely procedural, and rather low-level. Pointers to memory, no nifty features like garbage collection, and all that stuff. C is nice-to-know anyways, since a large variety of other languages has its syntax based on or derived from C syntax. PHP looks like C in some way, Java does, also C#, and many others. Using it however is a bit more difficult, since you have to do everything yourself - no strings built-in, take care of memory allocation and deallocation afterwards, and forget a check to see your app blow.
C++ is more like a mix of the two worlds. It looks like C, as the creators aimed for/were driven to "be backwards compatible" to C. Use C-Code in C++, works all the way (with minor fixes, if any). Mix in some sort of object-oriented stuff, call structs "classes" and let the coder add methods to it. Look, its an object! C++ provides new features, and keeps the "problems" of C - no garbage collection, and you still have to take care of your memory.

Saying "C++ is better than C" always depends on what you want to achieve with it. If you want slightly easier development, since someone already took the work of creating a linked-list (stl vectors for you), you might take C++. No need for objects, attaching methods to them, or encapsulation of data that provides some sort of (fake) access control, you might go with C aswell. Theres nothing you can do in C++ but can't do in C (classes are just structs, member methods become "static" methods that take the struct explicitly, templates can be written as macros, etc etc).
It's all a matter of taste. Some say C++ is bloated, C is error-prone, C++ is superior, C is superior, C++ is bad, C is bad. They're all right in some way, and also wrong.

If you want to learn a language, and know zero-to-nothing, you might want to start off with C# at all. Friendly IDEs (SharpDevelop for Linux, Visual C# Express for Windows) that help you, fairly good documentation (even if its M$/MSDN, it does help!) and gets you started quickly - also gets you done quickly, as you don't have to focus on memory allocation, range checking, all that stuff (not quite correct, but this explanation suffices for now).
Knowing another language, but not being familiar with C/C++ Syntax, you might want to start with C; and get through procedural stuff first. It should teach you the basics about memory management, pointer arithmetics, and why something happens if you write a line of code.
Starting off with C++ is not the best way to get into coding, unless you really want to push your luck.

Feel free to pm me with your random rants about it, I'll silently ignore them. Questions, just ask.
BhaaL
Poster
Poster
 
Posts: 270
Joined: Sun Apr 13, 2008 11:16 am
Blog: View Blog (0)


Re: C or C++

Post by macrocat on Sat Feb 21, 2009 3:23 pm
([msg=18369]see Re: C or C++[/msg])

I've never understood the point of objects or classes.

Why do you need classes? Structs provide the same functionality with a lot less useless "GET" functions. All this just to protect data? It's really your own fault if you modify something that you're not supposed to. Having the compiler spit out an error seems to be overkill.

I'm starting to learn Python, and I've compared C++ to knowing how to drive a car but being deathly afraid of highways; you know how to do it, but you can't get anywhere with it.
macrocat
New User
New User
 
Posts: 27
Joined: Wed Jan 21, 2009 8:12 pm
Blog: View Blog (0)


Re: C or C++

Post by BhaaL on Sun Feb 22, 2009 6:26 am
([msg=18397]see Re: C or C++[/msg])

The idea behind is proper encapsulation. You got a shopping cart class that allows you to put things in and out, but you cant tell the shopping cart to pay itself. And you might have a counter class that sums up the prices for items and then charges you money, but wont put stuff into your shopping cart. Properties ("a lot useless GET functions") are just a small part of it.

As I said already, theres nothing you cant do procedural that works object-oriented.
BhaaL
Poster
Poster
 
Posts: 270
Joined: Sun Apr 13, 2008 11:16 am
Blog: View Blog (0)



Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests

cron