As a mathematician, my training is to define my terms before I use them. As a computer programmer, I recognize that there are sometimes good reasons to call a method/function/procedure before its full definition has been given. But all other things being equal, I still prefer to define helper methods before they are used rather than afterwards.
However, in TeX programming, the convention seems to be backwards. A simple example of this is the following, taken from this answer:
\newcommand{\utriangle}{\text{\doutriangle}}
\newcommand{\doutriangle}{%
\linethickness{.1ex}%
\setlength{\unitlength}{.8ex}%
\begin{picture}(1,1)(0,-1)
\polygon(0,1)(1,0)(1,1)
\end{picture}%
}
(Note: This is taken out of context; don't try to run it by itself.)
Another example is Donald Knuth's definition of the \loop ... \if ... \repeat construction:
\def\loop#1\repeat{%
\def\body{#1}\iterate}
\def\iterate{%
\body \let\next\iterate
\else \let\next\relax\fi \next}
\let\repeat=\fi
Although I have not tested this, it looks to my eye as if defining \iterate before \loop would have exactly the same effect. [I honestly have no idea about \let\repeat=\fi, since I know \fi constructions can be rather finicky.]
Is this convention arbitrary, or is there a good reason for it? For instance, are there common situations in which the code will break if the helper macro is defined first?
\edefis used). – Joseph Wright Mar 09 '14 at 18:03\utriangle". – cslstr Mar 09 '14 at 18:03papercode until you see the part you care about, and then work backwards. Either way, if readability is important, I imagine giving informative names to the helper macros is crucial. Knuth's example above does a fairly good job of this, but most other examples I've seen don't. – Charles Staats Mar 09 '14 at 18:11