Switching from Matlab to C++

Daniel Duffy

C++ author, trainer
Good question! I'm going to sit right down and write an answer. Need a few days.

Generalising "does C++ prepare you for the functional programming onslaught?"
Savvy C++ programmers should be able to make the switch to FP. They have been using FP unknown to themselves (STL, boost function, lambda). Many design patterns (e.g. Visitor) are workarounds for constructs in FP.

And having a maths background is useful as well as the 'cinderella' Category Theory.

But FP will never overturn C++. C++ 11 and Boost will evolve into and/or subsume FP IMO.
 

bigbadwolf

Well-Known Member
Savvy C++ programmers should be able to make the switch to FP. They have been using FP unknown to themselves (STL, boost function, lambda).
I don't dispute it. I was wondering if a C++ background affords them a head start in picking up FP. I'm not sure.

And having a maths background is useful as well as the 'cinderella' Category Theory.
I ordered some coding-oriented books on category theory last week.

But FP will never overturn C++. C++ 11 and Boost will evolve into and/or subsume FP IMO.
Could be. C++ will probably become even more unwieldy than before. It's probably the topic for some other (probably already existing) thread, but arguably first exposure to coding should be FP rather than, say, C++.
 

Daniel Duffy

C++ author, trainer
If we take the example of F#, moving to it from C++ is tricky mainly because of the syntax.

Plan B is us to use C# and call F# code from it.

But I think C++ and F# are light-years apart.

BTW there's a nice "Category Theory Primer" pdf on the google.
 

Polter

Active Member
arguably first exposure to coding should be FP
I actually agree with this -- FP PL first, before any PL that allows you to (or at least doesn't discourage you from) programming in imperative style (so, say, Python, while simple, would be out for the exact same reason). At least for math or CS majors this shouldn't be a problem. IMHO it's much easier to transfer from FP rather than to it. As I've mentioned earlier, I think Scheme has a lot going for it:
it has basic/minimal syntax (some would say it has no syntax at all) which doesn't obstruct from learning the core concepts, there's an excellent book series (SICP, The Little Schemer, The Seasoned Schemer, The Reasoned Schemer).
 

JackF

New Member
I saw Daniel Duffy mentioned Python being useful, if you ever did use it I know BAML and JP Morgan use it as the back bone of their firms (thanks to the same man how put together Goldmans SecDB/slang) and it would allow you to prototype quickly (not quite as quick as MatLab) and integrates in very nicely with C++. Only issue is multithreading is a bit of a nightmare so you might have to thread in C++ anyway.
 

Daniel Duffy

C++ author, trainer
A huge generalisation is that C++ is more suitable for mainsteam engineering applications while FP languages have traditionally been used in CS environments.
 

danielruc

New Member
Hi, everyone. I am a student persuing a master degree of financial engineering and I had begun courses like programming. As a beginner, I choose matlab since it's easier to learn. However, I also heard that in finance, it's really important to learn C/C++ since there is something matlab cannot do. I'd like to ask in what aspect does C/C++ outpeform matlab? Is there anything that C/C++ is capable while matlab isn't?
And since I am a beginner, whould you please give some suggestions on learning to program?
Thanks a lot!:)
 

JackF

New Member
(as one student to another) so they are both turing complete with a VM, I/O, user interface constructs, mathematical operators, datatypes, user-defined-functions, etc. - if thats what you mean, MatLab gives you a lot of ability to do things quick while c++ with a good compiler lets you do things that will run quick. Prior to MatLab 7.4 for instance, there was no multithreading - which means you could only run a single thread (code) sequentially. So say you wanted to evaluate the integral x^2 between 0 and 10, your computers ALU doesn't have an integration function so it would evaluate x^2 at a whole bunch of points and add them up, this could be made quicker if you had 10 processors though and each only looked at 0-1, or 1-2 etc -> it would be 10 times faster (roughly because you have to open threads and add results...) but you get the idea.
Now while newer versions of matlab have multithreading, c++ still gives you more flexibility to the lower level aspects of the computer.

*Apologies if my example wasn't the best one but I just wanted to illustrate it a bit so it would make a bit more sense :P
 

Andy Nguyen

Member
You may not use C++ at all in your job and instead use VBA/Matlab, etc but during interviews, they usually ask technical questions on C++ so it pays to know the language well.
There is a reason they use C++ as a technical filter during interviews.
Just take a look at the interview books on our reading list and see for yourself the type of programming questions in these books.
 

Polter

Active Member
You may not use C++ at all in your job and instead use VBA/Matlab, etc but during interviews, they usually ask technical questions on C++ so it pays to know the language well.
There is a reason they use C++ as a technical filter during interviews.
Just take a look at the interview books on our reading list and see for yourself the type of programming questions in these books.
A few notes regarding the "C++ (ordered by level of difficulty)" section:
- Deitel & Deitel's book has a new edition
- Lippman's (or Stanley B. Lippman, Josée LaJoie, Barbara E. Moo's) book has a new edition
- given that you're listing C++98/03 books anyway, I think there's a prominent missing position: http://www.acceleratedcpp.com/ // given the fact that Bruce Eckel's books assume C knowledge and this one doesn't I'd place it before (i.e., as easier than) "Thinking in C++"
- Stroustrup's book is going to have a new edition very soon: http://isocpp.org/blog/2013/01/stroustrups-tour-of-c-third-chapter-posted
- on a side note, I don't think that "C++ Primer" is any harder than Stroustrup's book, it may even be easier (it's a somewhat different style of presentation, so hard to compare directly -- e.g., Stroustrup's early overview of available programming paradigms assumes some level of programming maturity, that being said "C++ Primer" isn't the first programming book either; there's another, much more entry-level book from Bjarne, http://www.stroustrup.com/programming.html)
- last but not least: perhaps just linking to the following would be a better idea:
http://isocpp.org/get-started
http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list
// the first one is official and up-to-date, the second one should also stay updated :)
 

aminya

New Member
Get some numerical linear algebra lib.
I think you might like Eigen: Eigen: Main Page
A short ASCII reference with Matlab translations: http://eigen.tuxfamily.org/dox-devel/AsciiQuickReference.txt
Active and helpful community forum: Eigen • KDE Community Forums

Blaze is perhaps worth looking into: Google Code Archive - Long-term storage for Google Code Project Hosting.

Note that preferably you want to focus on the libraries that beat (or at least match up to) Intel MKL, since that's what MATLAB's relying on for its vectorized operations (of course you're going to easily beat it for the non-vectorized ones, but why settle for less), and it seems sub-optimal to use anything slower; that's also the reason I'm suggesting either Eigen or Blaze:
Benchmark - Eigen
Google Code Archive - Long-term storage for Google Code Project Hosting.

// From the above benchmarks, the Armadillo+MKL combination doesn't look bad either, but note that you must get an external BLAS lib (like MKL), otherwise Armadillo is not going to be very useful or fast (it takes a different design approach, relying on an external optimized BLAS instead of providing optimized numerical linear algebra implementation itself -- discussing the relative merits & trade-offs is beyond the scope of this post, but be aware that what it means for the end-user (you) is that you need to get it separately & set it up):
Armadillo: C++ library for linear algebra & scientific computing

From what I can tell, the same is true for Blaze:
"Additionally, for maximum performance Blaze expects you to have a BLAS library installed (Intel MKL, ACML, Atlas, Goto, ...). If you don't have a BLAS library installed on your system, Blaze will still work and will not be reduced in functionality, but performance may be severely limited. Thus it is strongly recommended to install a BLAS library."
Google Code Archive - Long-term storage for Google Code Project Hosting.

In contrast, Eigen is a standalone library, highly competitive with MKL on its own.

For more choices, see this thread:
http://www.wilmott.com/messageview.cfm?catid=44&threadid=87551

It's worth mentioning that recently the Numerical Template Toolbox (NT²) has restarted its development:
http://github.com/MetaScale/nt2
It's interesting, since "provide a simple, MATLAB-like interface for users" is one of the guiding goals.
For instance, it supports select-all-rows/columns operator (colon in MATLAB, underscore in NT2) and vectorized functions:
Code:
MATLAB: B = I(:,:,3); ...; V = min(abs(0.5.*R-0.419.*G-0.081.*B),240);
C++ w/NT2: B = I(_,_,3); ...; V = min(abs(0.5*R-0.419*G-0.081*B),240);
Presentation:
[PDF] https://github.com/boostcon/2010_presentations/raw/master/thu/falcou_lapreste_boostcon.pdf
[Video] http://blip.tv/boostcon/joel-falcou-jean-thierry-lapreste-the-numerical-template-toolbox-boost-ed-generic-array-library-for-high-performance-computing-4204932
However, it's a relatively new (revision of the) library under active development, so for starters you may want to consider one of the aforementioned ones at first.
Any update on this after 5 years? (Specifically for embedded processors like ARM cortex A9)
 
Top