Thread: Is C/C++ suitable for an econ student?

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    32

    Is C/C++ suitable for an econ student?

    Hi,

    I'm not becoming a professional programmer, because I'm pursuing an econ degree. I'm now learning C++ by myself and getting a lot of help on this forum.

    Is learning C++ useful for me in the sense that once I get the good basics of it I will find it easier later on when learning some high-level languages like Matlab/R?

    My goal is very modest: just want to be able to write econometric estimation procedures on my own, instead of relying on the point-and-click menus from econometrics softwares like Stata/Eviews, writing simulation in statistics, etc...

    Thanks a lot

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    No. Unless you plan on working as a general programmer, learning anything other than the language you intend to use is foolish. The time you'll spend learning the basics, quirks, and best practices of one language can be spent mastering the language or environment you intend to use.

    If you plan on using Matlab, learn to use Matlab. Later, if you find you've mastered Matlab, feel free to pursue other languages.

    Soma

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    You'll get different opinions on this, (whether you should start to learn programming on a low or high level) but I think you should just start by learning Matlab. I mean, that seems like what you want to use as an economist so why wait.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Learning any programming language is a useful exercise in itself, since it develops key skills in being able to logically think through problems.

    As for which language to learn first - it doesn't matter.
    Having learned one (doesn't matter which), learning the next one will be somewhat easier. After half a dozen languages, they all start to look pretty much the same anyway (to the point you can start doing useful stuff in minimal time armed only with a suitable reference manual).

    Besides, you may get really into Matlab to the point where you need to start writing plug-ins for it (in say C++). At that point, you'll be riding high compared to your colleagues
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by phantomotap
    If you plan on using Matlab, learn to use Matlab. Later, if you find you've mastered Matlab, feel free to pursue other languages.
    Quoted for truth. You might as well start "riding high compared to your colleagues" from the beginning, with time to spare to learn C++ later so that you'll still be ahead of them when being able to write plugins in C++ might be a bonus.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    C and C++ are both ponderous compared to more specialized, higher level, and scripting or interpreted languages.

    I don't know anything about economics and computing but if there are more specialized, higher level languages available for your purposes, you might as well start there. That way, even if you are still interested in C/C++, you will have something to contrast it with and decide if it is really necessary to be writing 5-10 times as much code in order to accomplish more or less the same thing.

    If Matlab is too specialized and you have some interest in general programming that it can't provide, I would check out python, perl, ruby, or VB .NET before C/C++.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Well not to be the odd-man out here but I would suggest learning C and or C++ because of Matlab. Not that learn either with help with the other directly but....I used to work at a medical device manufacturer where the lead scientists were great using Matlab but then had to explain the workings of the Matlab stuff to me so I could express it in C or C++ for the company software product. The few scientists that knew some programming were able to get a lot of it done by themselves but many were lost once they tried to set foot outside of the realm of Matlab.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  8. #8
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    I'd say learn Matlab first. That way, you will get more immediate benefits for the applications you have in mind.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  9. #9
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    I would learn your target language first. If you need to write a plugin or something later, it'll probably just be a matter of looking at a plugin example and learning some math functions in your case. Besides, you can write your own functions in MATLAB... Learning C/C++ will only enable you to write a faster program (who cares) and teach you about the inner workings of the computer.

    I don't know exactly what it is you want to do, but if you're just going to be doing like tables and charts of statistical analyses with raw data, I'd check out SAS. SAS is so win, I love it.

  10. #10
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    The only thing I know of from C that really applies to MATLAB is the concept of memory allocation. If you want to write fast and efficient MATLAB code, you should try and declare an empty array or matrix before doing any work so that it doesn't have to reallocate the size of the data structure every time you touch it.

    Also, vectorization is key. C would teach you to do something like this:
    Code:
    for (i=0; i<100; i++)
         mysum+=sin(i);
    However, the equivalent code in MATLAB would be very slow, you would do well to vectorize it:
    Code:
    i=0:99;
    mysum=mysum+sum(sin(i));

  11. #11
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by Epy View Post
    However, the equivalent code in MATLAB would be very slow, you would do well to vectorize it:
    That is actually less true since a couple of years ago. Matlab now comes with a Just-in-time compiler which compiles for-loops no native code and achieves decent execution speeds.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  12. #12
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Might not always be running a script though, it's just better to get in the habit of vectorizing.

  13. #13
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Epy View Post
    The only thing I know of from C that really applies to MATLAB is the concept of memory allocation. If you want to write fast and efficient MATLAB code, you should try and declare an empty array or matrix before doing any work so that it doesn't have to reallocate the size of the data structure every time you touch it.
    Dynamic arrays in the higher level interpreted languages -- perl, python, etc, where an array is an array, it's dynamic, it's managed for you, and that's it -- are allocated in power of two blocks. I've seen plenty of tests demonstrating these things will execute as fast as a compiled C/C++ equivalent, tho of course many many people are still in howling fantoid denial about this.

    He's an economist. He doesn't need to learn about memory management. Unless you really want to write software or something, it's a waste of time.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  14. #14
    Registered User
    Join Date
    Dec 2009
    Posts
    32
    Thank you all for the suggestions. They're all very useful to me. When you began learning the very first language years back, did you fall into some sort of situation where you were really wandering about which language to learn instead of concentrating on a language first and then moving on to others? I've been using SAS for 1 year now, and now I'm beginning to learn C++. When I took courses from 2 econ professors, one of them said human time is very precious now, and that today speed is not a problem as compared to decades ago, so why not learn C/C++, etc.... instead of R/Matlab? The other said we should learn C/C++ because it gives you complete control over the process of doing something, and that only by doing so does a student truly understand what he is doing. In other words, programming (in C/C++, etc...) is understanding, as he said.

    When I am learning C++, one obvious thing I notice is that it's far more difficult than Matlab/SAS, but it's a lot more interesting. In fact, it DOES help me learn something effectively, because it forces me to learn it and understand it before writing a program. For example, when I use a regression procedure from SAS, I just call it and taking it as given that it's 100% correct and standard, and don't know why. Now, with C++, I must learn every single details of the procedure, ....

    Thanks a lot

  15. #15
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    If you feel this way: "one obvious thing I notice is that it's far more difficult than Matlab/SAS, but it's a lot more interesting" then stay with it -- that's a choice, that's how you feel about it, and no doubt it is more interesting, just obviously being more difficult it will now sap more of your mind and time.

    Are you sure you want to be an economist?
    Last edited by MK27; 05-03-2010 at 09:15 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Updating in a sequential file?
    By Ronnyv1 in forum C Programming
    Replies: 1
    Last Post: 03-24-2009, 04:41 PM
  2. Database assignment is Killing me!
    By Boltrig in forum C Programming
    Replies: 2
    Last Post: 11-29-2007, 03:56 AM
  3. LinkList Sorting in C
    By simly01 in forum C Programming
    Replies: 3
    Last Post: 11-25-2002, 01:21 PM
  4. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM