Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nobita

macrumors 6502
Oct 5, 2008
425
2
La la land
I'm a C++ programmer for three years. Trust me it's got a steep learning curve, but C is worse! It's so much easier to get syntax wrong in C, in addition C doesn't have those library you can use to make your life easier (such as vector, stack, queues, strings, list, you name it.)
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
Help me find more...

okay... how about exception handling, function overloading, operator overloading, templates… const, references, static/dynamic/const_cast... oh and let's not forget all the object orientated stuff. Even if you don't like or don't understand oop you can still make great use of parts of std, eg std::string etc. If you do that then you'll also appreciate the benefits of resources being deleted when they go out of scope. Oh and another benefit is the ability to compile standard C.

So if I was starting off, I would learn C++, starting with the basic C core and then expand out into the C++ 'parts' in small steps. Once you've learnt C, I'd say it's probably a good idea to catch up with the rest of the world and learn even just a little bit of oop.

b e n
 

trule

macrumors 6502
Mar 16, 2007
310
0
OK, So i have learned C++ a little bit..

What do you guys think about this situation..?



Do you have a reason to learn C or C++? Other than causing yourself pain? C and C++ are real engineering languages best used for solving real engineering problems.


Try to stick with Perl, PHP, Ruby...or if you must, Java.
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
I won't elaborate on the matter much, because I am not very fond of threads that end up in a disagreement over what programming language is better.

C++ exists for a reason. So does C. If C++ was the truly better than C, then no one would program in C. If C was better than C++, then the need for developing C++ would not have existed, and there would be no C++.

As for some advice for the thread starter... Whatever you choose, you will surely need to learn the language's relative in order to do some things. For example, if you learn C, there is no way you will avoid learning at least some features of C++ in the future, and vise-versa.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
Yes i do, i have to learn C++ at school... :)

It sounds like we could have saved a lot of time if we knew that in the first place =). It sounds like the decision is made for you, so just focus on C++ now, you can always go back and learn C later.

-Lee
 

jw2002

macrumors 6502
Feb 23, 2008
392
59
So which language should i learn then? C or C++?

Most definitely C++ because it is better to learn the object oriented paradigm as soon as possible. Some people will pooh pooh C++ as being only marginally better than C (such as stricter type checking), but that's ignoring the tremendous potential and advantage of C++: it's an OO language.

Also, responding to part of the first post, just because you are using C++, it doesn't mean you have to use <iostream> for your I/O. Feel free to use <stdio> if you really have the need for both C and C++ modules to access the same file descriptors and keep I/O synchronized.
 

MacRumors Guy

macrumors member
Sep 17, 2008
82
0
okay... how about exception handling, function overloading, operator overloading, templates… const, references, static/dynamic/const_cast... oh and let's not forget all the object orientated stuff. Even if you don't like or don't understand oop you can still make great use of parts of std, eg std::string etc. If you do that then you'll also appreciate the benefits of resources being deleted when they go out of scope. Oh and another benefit is the ability to compile standard C.

Exception Handling is an issue of much debate. however I'll give you that.
  • Function overloading Not really needed, if the functions are different you just describe the diference in its name.
  • Operator overloading Dangerous specially when combine with the myriad of C++ "features".
  • Templates Hard to program correctly (past trivial stuff), hard to debug. Actually I had more success debugging data structures purely defined in macros than templates lol.
  • const C has const?
  • casts Never had problems with either casts (C and C++ casts).
  • object oriented stuff is this and advantage or a disadvantage?
 

stuarthatto

macrumors regular
Nov 5, 2008
135
0
As a beginner, yes the exact syntax is what you care about now. But later what matters is how to break big problems up into small problems and those into smaller problems in such a way that the little problems become independent from each other.

Bingo! Little problems are easier to solve, code is more compact, more efficient, easier to debug, easier to read - and makes code RE-USABLE!

Took me ages to stop programming a problem top to bottom, branching, jumping, subroutining and so on.... but breaking a problem into its smallest parts is the secret with C++ and Java I guess
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
Hi MacRumors Guy

I don't really understand what you are arguing about... the C++ features that you're dismissing are at the core of the things you like and mentioned in an earlier post!

b e n
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
So after a week of back-and-forth, we've learned that some people prefer C++ and some prefer C, and both have problem domains that they are well suited to, and you won't be harmed by learning either first. We've also learned that you need to learn C++ for school, so that seems to make the decision pretty easy. I am sure we could keep this argument going for another few weeks, but at the end nobody's mind will be changed, and you will just have 100 differing opinions on this matter.

My point is that there is no right or wrong answer. So you don't learn OOP right away? That won't kill you. There are non-OOP languages you might want to use in the future, so knowing how to be effective without OO isn't going to hurt you. So you don't learn to manage memory as well using malloc/free right away? Big deal. It's useful, but you can learn it later. Just get coding. You will be fine.

-Lee
 

MacRumors Guy

macrumors member
Sep 17, 2008
82
0
Hi MacRumors Guy

I don't really understand what you are arguing about... the C++ features that you're dismissing are at the core of the things you like and mentioned in an earlier post!

b e n

Minus the fact that the std templates are already done!
 

Sander

macrumors 6502a
Apr 24, 2008
521
67
Exception Handling is an issue of much debate. however I'll give you that.

Programming languages are an issue of much debate.

Also, I heard that screwdrivers are very dangerous if you poke yourself in the eye with them. I'll stick to hammers, thank you very much.
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
Minus the fact that the std templates are already done!

Okay I see where you're coming from I think... using C++ as a souped up C. Sounds like a good path because you would be learning the core, C foundation anyway, yet be exposed to some of the harder aspects of C++ but in an easy accessible manner.

b e n
 

jw2002

macrumors 6502
Feb 23, 2008
392
59
  • Function overloading Not really needed, if the functions are different you just describe the diference in its name.
  • Operator overloading Dangerous specially when combine with the myriad of C++ "features".
  • Templates Hard to program correctly (past trivial stuff), hard to debug. Actually I had more success debugging data structures purely defined in macros than templates lol.

Gotta disagree on all these points.

For instance, function overloading is awesome because it decouples the interface from the implementation. A complex number in C++ can call a function named sin() which accepts a complex number and properly calculates the complex sin. This is provided through the standard template library. So from a scientific programming standpoint, C++ is superior because the formula written on the page can be transcribed into much more readable code. In C, complex numbers are a hot mess.

Operator overloading is not dangerous. Again, the disciplines of science and math use operator overloading in their very notation! We use the + and - sign for scalar, vector, and matrix addition. So C++ facilitates what has already existed in mathematical notation for centuries. I will agree that indiscriminate operator overloading can be inappropriate (such as making the + operator perform division), but that boils down to the same thing as giving a misleading name to a function.

Templates can be tricky, but if you find yourself writing a big one, then why not consult the standard template library first? You can probably incorporate one of those through inheritance, containment, or some design pattern and save yourself a ton of time from reinventing the wheel. Templates provide all the advantages of macros along with being type-safe. And no, macros are not easier to debug than templates. Good luck figuring out the error when that 25-line macro gets expanded into the middle of an if statement!

All of the above concepts can provide clear benefits even for non OO-aware programmers.

Furthermore, C++ has one more biggie over C: the reference. In C every pointer dereference "->" is a ticking time bomb. The reference in C++ allows all of the low level detailed modules to assume that they are dealing with objects directly and eliminates the need for pointer dereferencing. Thus any pointer bugs will rear their heads either at compile time or in a very high level module of the C++ code.
 

MacRumors Guy

macrumors member
Sep 17, 2008
82
0
Gotta disagree on all these points.

For instance, function overloading is awesome because it decouples the interface from the implementation. A complex number in C++ can call a function named sin() which accepts a complex number and properly calculates the complex sin. This is provided through the standard template library. So from a scientific programming standpoint, C++ is superior because the formula written on the page can be transcribed into much more readable code. In C, complex numbers are a hot mess.

The situations where function overloading is usefull or recommended are so trivial that using a more descriptive function name instead is not that much of a deal. BTW: function overloading is also a major pain in the ass for C++ who do cross plattform development thanks to C++'s type coercion plus the different disambiguation rules each compiles uses.
C99 has support for complex numbers. The GNU complex library also supports complex numbers. For you is that much more painful to call csin instead of sin?

Operator overloading is not dangerous. Again, the disciplines of science and math use operator overloading in their very notation! We use the + and - sign for scalar, vector, and matrix addition. So C++ facilitates what has already existed in mathematical notation for centuries. I will agree that indiscriminate operator overloading can be inappropriate (such as making the + operator perform division), but that boils down to the same thing as giving a misleading name to a function.

Nice comparison except for a very subtle detail, in math those operators have no side effects!

Templates can be tricky, but if you find yourself writing a big one, then why not consult the standard template library first? You can probably incorporate one of those through inheritance, containment, or some design pattern and save yourself a ton of time from reinventing the wheel. Templates provide all the advantages of macros along with being type-safe. And no, macros are not easier to debug than templates. Good luck figuring out the error when that 25-line macro gets expanded into the middle of an if statement!

What if I can't? Do you think a C programmer reinvents the heel more often because they don't have the object oriented mondo jambo?
When you define a macro at least you know how it expands.

[Last post]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.