Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Good programming practice in Mata


From   Gordon Hughes <[email protected]>
To   [email protected]
Subject   st: Good programming practice in Mata
Date   Fri, 29 Jun 2012 18:17:38 +0100

This is a rather belated follow-up to some advice posted on May 16th by Bill Gould in response to a query about compiling Mata subroutines from an ado file. The link is:

http://www.stata.com/statalist/archive/2012-05/msg00712.html

The gist of the advice, as I understand it, is that it is more efficient to embed Mata functions in an ado file rather than precompile them and access them through .mo files or .mlib libraries. Now, I am probably older than Bill and I learned to program in Fortran on large IBM mainframes, so this advice caused my eyebrows to head skywards since it runs completely counter to traditional good practice.

There are many reasons for developing libraries of separate subroutines that can be re-used or maintained more easily as discrete bits of code rather than being embedded in one large and perhaps poorly-documented program file. So, I assume that this advice does not apply to the process of developing new programs. On the other hand, I can understand that a big advantage of embedding Mata functions in the ado file which calls them is that all of the function names are private, thus avoiding potential conflicts with functions with the same name that do something different.

However, I understand the advice as suggesting that Stata will execute a program more efficiently if the production version takes the form of a single - or small number - of ado-files with embedded Mata functions and no associated .mo or .mlib files.

Is my understanding correct? And, if so, why? Is it just that just-in-time compilation of Mata code is so fast that the overhead of compiling the functions when they are first called is very small relative to the overhead of searching for the routines in the .mo or .mlib files? Finally, if this is best way of producing production versions of programs, then it might be helpful to publicise the advice as I cannot recall having seen it previously in any Stata manual or, for exampling, in Kit Baum's book on Stata Programming.

Gordon Hughes
[email protected]

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index