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: how to be -assert-ive


From   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   st: how to be -assert-ive
Date   Thu, 30 Sep 2010 07:52:54 -0500

This was the title of Bill Gould's Stata Tip#3 in the first issue of
Stata Journal; over 10 years, it has received a whopping 2 citations.

I wonder how often -assert-s are used in ado code? E.g., I know that
some sort of -egen- command should retain the pattern of missing
values from the source variable(s) to the newly generated variable; or
a regression command should return R^2 between 0 and 1; or a
prediction command should return non-negative values; after -mi-, I
would expect the missing values to be replaced by non-missing; etc.
Sometimes I do see -assert-s when I peek at the official Stata code,
but not every program would use it. Bill Gould's recent "Missing
manual" talk gives an example of prototypical code development in
which the program goes into an ado file, and a test script checks its
performance against the expected behavior using -assert-; and that's
how certification would usually proceed (see another WG's paper in
Stata Journal 1 (1) ).

Now, I wonder if -assert-s in ado code is a desirable practice, and
whether other people use it a lot. On short ten line programs, an
extra couple of -assert-s means 20% increase in # of lines, and most
likely a certain (although not necessarily a 20%) increase in
execution time. On long programs where a lot is going on, including
some convoluted -sort- operations, let alone numeric optimization or
root finding, an extra -assert- or two or three or five are negligible
in overall timing. As a matter of (i) good style and (ii) robust
programming, do I need to put more -assert-s in my code?

A command with similar intention is -confirm-, and again it is used in
the official Stata code, usually to check inputs. And of course there
is -assert()- in Mata, as well.

-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.
*
*   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