Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mata and C++

    Mata has a C++ like syntax according to the Stata manuals. From your experience how similar is actually the syntax? Can someone with knowledge of Mata jump to C++ programming relatively painlessly?

  • #2
    Not that easy but depends on which C++ do you want to use. C++ is an extremely large language (compared with Mata or C), with many somewhat obscure features. It would take you years to learn those well enough.

    On the other hand, if you only want to do "C with classes", the jump wouldn't be that large, but you will still need to learn a thing or two about types, memory, etc.

    Comment


    • #3
      I think an average c++ (or any other c-like language) programmer should find the mata syntax and many of its concepts familiar. They still need to learn about the conventions used to write effective mata programs especially the way they interact with the host environment: Stata proper. Generally, mata is well designed and has sensible conventions. But, there are rough edges (e.g., basic c constructs such as "const" and "switch" are not implemented) and curve balls (e.g., vector [array] addresses starting from 1 rather than 0). There are also no solid libraries beyond what is provided by Stata runtime. On the other hand, the runtime takes care of managing and ably executes the byte code.

      Unfortunately, neither the compiler nor the runtime is very helpful in debugging, sometimes even printing misleading messages about errors. The runtime does not even specify the line number or the routine name of the offending code. Since there are no debugging facilities to talk of, you are reduced to inserting print stmts all over the place in the hope of locating the offending code. This, plus the lack of namespaces, makes Mata a functional language for developing simpler Stata routines, but not one that I would use for large projects. It is by no means a replacement for a general-purpose programming language, so people coming from the c, JAVA or Go world, are warned not to expect much.

      Comment


      • #4
        Mata will provide line numbers for run-time crashes if you do
        Code:
        mata set matalnum on
        . (But you should turn the setting off when a project is finalized because it prevents the compiler optimizer from running.) I've never found the error messages that misleading.

        Comment


        • #5
          There are some other pitfalls as well. For example, it isn’t possible to write overloaded methods/functions. There are also some differences in the file structure between C/C++, Java, and Mata. There aren’t really any import statements that I am familiar with, and definitely does not seem to be any analog for header files. Some of the very basic concepts would definitely transfer, but I suspect there would be a nontrivial amount of difference between Mata and C++.

          Comment


          • #6
            How do I estimate the real return to physical capital?

            Comment


            • #7
              Originally posted by Osman Suliman View Post
              How do I estimate the real return to physical capital?
              You can begin by reading this, especially, Item 1.5.

              Comment

              Working...
              X