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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Good programming practice in Mata


From   "William Gould, StataCorp LP" <wgould@stata.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Good programming practice in Mata
Date   Mon, 02 Jul 2012 09:34:59 -0500

Gordon Hughes <G.A.Hughes@ed.ac.uk> writes, 

    [In 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 [...] [which] runs completely counter to traditional good
    practice.

    [...] 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.

I need to clarify.  

    1.  Stata runs programs most efficiently when the Mata code is 
        pre-compiled and stored in a .mlib or .mo file. 

    2.  Gorden is absolutely correct when he writes that good style is
        to write general-purpose utilities and compile them into
        libraries for use by other routines.  This makes them globally 
        available and saves recompliation costs.

    3.  Nonetheless, every problem has some custom code associated with 
        solving it. 

    4.  StataCorp follows the practice of placing such custom code 
        into the ado-file.  Yes, that slows down the loading of the 
        ado-file, but not by much, and Stata is good at keeping 
        ado-files in memory, anyway, so ado-files are seldom reloaded.  
        The extra time of recompiling goes mostly unnoticed. 
        The advantages outweigh the disadvantages.  

Cheers, 

-- Bill
wgould@stata.com
*
*   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