• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Which Language - C or C++?

Joined
6/15/10
Messages
8
Points
11
Comp Sci at a good school, been working for a couple years, now getting into [quant] finance

Program was C++ focused but haven't been coding out of school, getting back into practice. From news and forums I know C++ is popular; but had a couple interviews lately with C questions

Is C used for more technical, lower-level programming like performance? Is C++ more for applications and implementations? I wasn't expecting so much emphasis on C

I'm figuring out if I should supplement my current C, C++ and Python book collection
 
Everyone has their own opinion on the matter, but I am of the school that one should learn C prior to learning C++. While C++ is a very powerful language, its core style really stems from C. Even now (for academic purposes), when I mostly use C++ (i.e. classes), I find it convenient to resort to old 'C-style' syntax in certain situations. Coding purely in C++, without knowing C and understanding Assembly in my opinion, can cause one to lose sight of the low-level nuances (i.e. memory/stack management) and not be able to code/debug securely and efficiently.

But to answer your question, there really isn't anything that is possible to do in C that is impossible to do in C++ and vice-versa. It is really a matter of coding preference. While industry probably prefers pure C++ for readability, portability, and its many great benefits, someone with my background (security) will generally code with whatever 'gets the job done' in the easiest way possible -- even if that means my code is nonsensical to others.
 
@APalley makes sense. what is your preferred Compiler & IDE for c/c++?
I have been using VC++ for years, and was considering using one of the open-source ones for portability (to mac, linux,...) like Code:Blocks, Netbeans....What's your view on that?
 
Changing IDE won't make your code more standard compliant - this is up to programmer, eventually with some help from compiler through corresponding flags that would check for the standard compliance etc. But indeed it's true that the community of programmers using VC++ is somehow least caring about standards and such: within this community, the line was always blurred between C++ standard functionality, functionality offered say through Win32 API, then through MFC etc. So if you really care about the portability of your code, it would definitely help if you try to build it using different compilers, and maybe on different operating systems. As far as I know, alternative IDEs you mentioned above are using GCC compiler suite under the hood, and GCC guys take standard compliance seriously, so it's definitely good choice in that regard.
 
I find it convenient to resort to old 'C-style' syntax in certain situations.
Can you give an example where C-syntax is more convenient than C++ syntax?

there really isn't anything that is possible to do in C that is impossible to do in C++ and vice-versa.
I definitely agree, but the ease and clarity of code from the C++ viewpoint makes the C solution "ugly".

someone with my background (security) will generally code with whatever 'gets the job done' in the easiest way possible
If you're doing this for solely your purposes and your own code, then that's fine. If I have to read your code, work with it, or maintain it later on ... :mad:

I've had interviews where they asked C questions too. I took C um ... years ago. In uni C++ was the norm. Sure there's lots of legacy code written in C, doesn't mean we can't implement code on top of it in C++, with some minor fixes. C++ >> C, so why not use it? C++ has been around for so long, that we should already be porting existing C code to C++ if you really want to avoid mixing C and C++.
 
C++ is more flexible I think and is more powerful if we combine the speed of development and execution of application together. But since C is directly written on assembler, you'll find C faster than C++. But C++ is more effective and widely used. Actually you can say that C++ is immortal language since you can find C faster and C# richer, but both of them have their downsides: C requires much more development time which is programming nightmare. C# on the other hand needs much less development time but is slower. So C++ is something in the middle having optimized the overall time to develop and tun the application.
 
robbry - How about both? Learn C then build upon that with C++?

There can be some difficulties to be considered. The most common ones are:

1- time. It's gonna take you much time (which might be of your concern) to learn both languages. You might rather want to stick to one language initially and follow it.

2-Syntax ambiguity. Unless you are so smart to avoid the syntax ambiguity, you'll have some techniques blended into mind and have trouble getting out to the right direction. Especially with the languages of the same root. C based languages all are like to one another. If it were about VB and C/C++, then it'd be ok since they have completely different syntaxes.

3-Language integration. Not with this case but some trouble can be encountered when using languages having different capabilities of interacting with databases/servers/COM/spreadsheets, etc. When you want to interact with the language codes you are forced to choose among those ones which can write platform independent codes to make the assembler standardize and read it.

In case of C and C++ this (3rd one) is not an issue to be feared of. They have ALMOST similar advantages and disadvantages - they are faster than improved C# and even Java in some cases. C is written on assembler directly so needs less execution time. But both have manual and ugly memory management...You have to dynamically destroy the objects created to prevent a memory leak. And many other similarities which make them compatible for interaction. I'd think about these issues when starting to begin learning 2 languages together.
 
practically speaking it makes no difference. When working with c code I often find myself writing c++ wrappers.
 
practically speaking it makes no difference. When working with c code I often find myself writing c++ wrappers.

They are much similar to one another than any other "base-derived" languages. For example C# emerged from C++ (and Java) but has more differences than C and C++. From practical point of view there is almost no difference. But in some limited scenarios I mentioned above(e.i. integration, speed, flexibility,etc) there can be found many critical differences forcing you to strictly choose one language over another.
 
1- time. It's gonna take you much time (which might be of your concern) to learn both languages. You might rather want to stick to one language initially and follow it.

I agree, time is often the deciding factor. However as for the other points you raised - I actually think they are good reasons to learn both :).
 
Can you give an example where C-syntax is more convenient than C++ syntax?
I find printf easier for formatted output than cout. sprintf for formatting strings. Other C string operations, such as strcat etc. I use memcpy's often for lower-level stuff. But that's just personal preference.

I definitely agree, but the ease and clarity of code from the C++ viewpoint makes the C solution "ugly".
If you're doing this for solely your purposes and your own code, then that's fine. If I have to read your code, work with it, or maintain it later on ... :mad:
Agreed :)
 
I agree, time is often the deciding factor. However as for the other points you raised - I actually think they are good reasons to learn both :).

I meant learning the languages simultaneously. I got your point though. ;)
 
But since C is directly written on assembler, you'll find C faster than C++.

This is wrong, C is not "written in assembler" - most of the contemporary C and C++ compilers are written in C (recently, some in C++: for example, the hottest compiler project at the moment is LLVM http://llvm.org/ and it's written in C++), but this has nothing to do with the speed of the code generated by these compilers - this speed is determined by the quality of optimization engine provided by the compiler. This optimization engine is in turn mostly affected by the complexity of the language, so for this reason C code are, speaking very generally, faster than C++ codes.

As for the order of learning: some time ago, I had opportunity to teach higher-level programming courses at an university, during several years of turmoil and experimentation with various approaches regarding introductory, and second, programming language. So I had to deal with kids that learned Pascal first and then Fortran, then with kids that learned C first and then C++, and finally with kids that learned C++ only. In my experience, those that had to start with C++, and learnt C++ only, can't code their way out of the paper bag. Those that learned C first were actually pretty good, and generally they knew their share of C++ even better than those that spent all of their time learning C++. But the best programmers were those first generations that learned Pascal and then Fortran, although I have to admit that they also had much more serious introductory course in computer architecture, that certainly helped them much in actually understanding what's going on under the hood.
 
Closer to the assembler the language is the faster it will be with no doubt. And C is directly the first language emerging from the assembler which made a widespread other programs. Number one (closer to the assembler), which is not the case with C# for example since it is a "grandchild" of C it is far away from assembler. Speed depends on the complexity of the language and the level of the library. For example we all know that C is much ruder than modern languages those emerged from it directly even C++ and C++ itself is ruder than C#. The richer the library is the slower the compilation time will be and this is the case with C#. What makes C faster than other languages is the soft library (I mean-not heavy namespaces) which of course includes complexity since if you need to construct some GUI application then you need to embark on heavy typing (type hundreds of code lines) while its "childs" can handle it in 5-6 lines of code. This is the complexity involved in constructing a robust, well defined and safe application which is higher in case of C, not as complex in C++ and even softer in C#. But again, I repeat, we have a trade off between development time and compilation time. I am still searching a perfect language to use for numerous simulations depending on size and mathematical difficulty and I cannot say C will handle it faster (overall time) than C++.
 
For example C# emerged from C++ (and Java)...

C# shares the same syntax as the C family of languages but it's closer to Java than to C++.

Number one (closer to the assembler), which is not the case with C# for example since it is a "grandchild" of C it is far away from assembler.

I would say that C# is the grandchild of Turbo Pascal since the author of the language is the one who introduced the world to Turbo Pascal and Borland Pascal, etc... but, again, C# is closer to Java than any other language in the C-syntax family of languages.
 
C# shares the same syntax as the C family of languages but it's closer to Java than to C++.

I would say that C# is the grandchild of Turbo Pascal since the author of the language is the one who introduced the world to Turbo Pascal and Borland Pascal, etc... but, again, C# is closer to Java than any other language in the C-syntax family of languages.

Nobody argues about it. C# can be considered as a Microsoft new version of Java. But it was written in C++ which itself emerged from C right?! That's what I meant there. Yes C# has almost the same syntax as C++ and C.
 
Back
Top