Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: Good programming practice in Mata


From   Gordon Hughes <G.A.Hughes@ed.ac.uk>
To   statalist@hsphsun2.harvard.edu
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
g.a.hughes@ed.ac.uk

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index