Announcement

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

  • #16
    Originally posted by Joro Kolev View Post
    Hence a fully reasonable policy here could be:

    1. If we use of scalars in our own do files, adopt a convention like I do, say variables always start with a lowercase letter, scalars and matrices always start with a capital letter.

    2. If we write ado code to be used by other people, we can just do what StataCorp does, call our scalars with names like _i, _j, __i, __j, etc, and if a conflict arises because the user has called something with this name, just blame it on the user [...]
    I tend to agree with 1; what you do in do-files is up to you and, perhaps, your collaborators.

    I tend to slightly disagree with 2. The user might have adopted the convention (as suggested in 1) that scalars always start with an underscore. Or, more likely, the user might not be to blame if they have called a command, community-contributed or by StataCorp, that has previously created and relies on (system) variables (or scalars) that start with underscores; psmatch2 (SSC) or mi come to mind. There really is no point in risking overwriting those variables. So, yes, we can do what StataCorp does: do not use "simple", permanent names, such as _i, unless you intend to leave them behind; in that case, ask or at least tell the user. Otherwise, use temporary names for intermediate objects that are not left behind (that is kind of the main idea of tempvar and tempname).
    Last edited by daniel klein; 18 May 2021, 02:15.

    Comment

    Working...
    X