1

I about to take some courses in Pattern Recognition. As i have no prior knowledge in either C or C++, my professors told me to learn a bit of one of them before the course, and learn more when doing the course.

Which one should i pick?

The prior knowledge in programming i have is limited to mostly C# but some PHP, SQL and Prolog as well.

Erik Karlsson
  • 570
  • 1
  • 6
  • 17
  • 3
    If you have limited time available then learn C. It will serve you well and can be used as a stepping stone to learning C++ later if you wish to. – Paul R Oct 18 '10 at 08:48
  • 3
    Why didn't you put that answer as an answer? – graham.reeds Oct 18 '10 at 08:50
  • 1
    @Paul: the opposite is true as well and I claim that the learning route C++ => C is better (easier, more effective) than the other way round. – Konrad Rudolph Oct 18 '10 at 10:02
  • 2
    @Konrad: you may be right, but C can be learned a lot quicker than C++, as it's a much smaller, simpler language, and it seems that the OP may need to get up to speed quickly in order to get some work done. – Paul R Oct 18 '10 at 10:16
  • @graham.reeds: I didn't feel that my contribution was substantial enough to warrant a complete answer, and expected to be deleting it later anyway, when more complete answers appeared. – Paul R Oct 18 '10 at 10:19
  • @Paul: well, I don’t agree that C can be learned a lot quicker than C++ (at least not a useful subset of it!). It’s true that “the whole of C” is an easier language than “the whole of C++” but that’s irrelevant in this context. C++ is much easier for beginners. For detailed arguments, visit the link I posted in the answer below. – Konrad Rudolph Oct 18 '10 at 10:19
  • 2
    @Konrad: well I don't want to get into a religious war here - I'm just basing my opinion on experience and on the apparent difficulties that so many C++ neophytes seem to have with what is, after all, a very large and complex language. – Paul R Oct 18 '10 at 10:21
  • I will take my time to learn myself c++, like the accepted answers says. – Erik Karlsson Oct 20 '10 at 09:27

5 Answers5

5

The choice of a low-level language like C or C++ probably means you are into performance at the cost of the development time.

If this is your first low-level language, then learn C. It is simple, robust and proven language, and it allows to write the fast code. It has a decades long record of portability. It is much easier to integrate C code with code written in other languages. With C++ it is too easy to make things wrong. C++ requires much greater degree of language mastery and much more programmer's attention to make things right. While it is possible to write fast code in C++, it's more of an art than doing the same thing in C.

If you have only a few months to learn, then at the end you'll be able to write an OK C code, but this time is simply not enough to get enough experience with C++, hence your C++ code written in the first year or two will be awful.

See, for example, severe criticism of C++ from Linus Torvalds: C++ is a horrible language and C++ productivity. Basically, it boils down to C++ being too complicated even for professional programmers, and C++ code being ambiguous with context-dependent behaviour (this may be considered a higher-level language feature, but it makes more difficult to reason about the performance).

One of the major open source libraries for computer vision, OpenCV, is available both for C and C++, but it is also available for Python, which is a much easier language to get the things done quickly (and also to learn as a first language). BTW, I assume if you manage to offload most of the work to the library, which itself is written in C/C++, the performance cost of Python won't be huge (but generally Python is 10x slower than C).

sastanin
  • 40,473
  • 13
  • 103
  • 130
  • 1
    While some of the points made by Linus are actually valid, most of his diatribes on C++ are horrible flame war starting rants (after all, Linus (co-) *invented* flame wars). Not a good source of objective criticisms. – Konrad Rudolph Oct 18 '10 at 10:06
  • Well, probably there are better sources, feel free to suggest. While I mostly agree with Linus, I don't intend to (re-)start the flame war. My main point is that it is better to start with pure C first, not that C++ should never be used by anyone. It's not a good language for the first student project (but may be suitable elsewhere). – sastanin Oct 18 '10 at 10:44
  • 2
    Though people who come from c generally have bad habits, usually with type safety and not using [RAII](http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization). – Grant Peters Oct 18 '10 at 13:41
4

Stroustrup (inventor of C++) argues that C++ is easier to learn than C:

There will be less type errors to catch manually […] fewer tricks to learn […], and better libraries available.

With that in mind, go for C++.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
3

C and C++ are fundamentally different in the way they approach programming. If you have experience with C#, C++ would be a choice since it is object oriented as well. Also, even though they are different, knowing C++ will let you read (and mostly understand) C code as well. Also, check out this question for some information on the differences between these languages.

Community
  • 1
  • 1
Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
3

I would recommend learning C++ as this probably be easiest if you know about classes etc from C#. Also you can write free functions in C++ but is harder to write classes in C.

graham.reeds
  • 16,230
  • 17
  • 74
  • 137
1

A standard library you will likely use is opencv.

C# will set you in good stead to master C/C++. You will probably be able to see through the opencv code examples and understand them.

You can likely get by with enough C you pick up from working through the examples and becoming familiar with them. The focus of the course will be on the algorithms and not how fancy your code is.

Sounds like a fun course! Good luck.

Will
  • 73,905
  • 40
  • 169
  • 246
  • 1
    Note that OpenCV has both C and C++ APIs, but it seems that the C API is more mature and more stable. (Of course you can still call the C API from C++, but that rather defeats the purpose of learning C++). – Paul R Oct 18 '10 at 10:18
  • Nobody masters C++! You just get a little better every time. – Grant Peters Oct 18 '10 at 13:38