[Tex/LaTex] How bad for TeX is omitting braces {}, even if the result is the same

best practicesbracessourcecode

Sometimes writing braces and omitting them produces the same result:

\tilde{\psi}  \mathrm{e}^{\mathrm{i} \pi}

vs

\tilde \psi   \mathrm e^{\mathrm i \pi}

Or (taken from Werner's comment below)

\frac{1}{2} vs \frac12

If that's the case, how bad for the quality of my code is omitting them? Of course, if one compiles a pair of formulas, there is no difference. But, since I ignore how TeX works, my point is: if one writes long codes with these habits,

  1. doesn't TeX go somehow crazy because I'm not writing as it expects?
  2. For instance, does it have any effect on how fast are long documents compiled? Any reason to keep them?

Best Answer

(Disclaimer: The question clearly says "even when the result is the same", which I answer by saying that when the result is the same, the result is the same. However, there are (numerous) examples when the result is not the same, see e.g. Frank Mittelbach's answer!)


There is only one valid answer in my opinion: From the TeX's point of view, if there is no difference, there is no difference (what a nice tautology). So from the TeX's point of view, it is not "bad".

As people say in the comments, the second point is about the legibility of your code to humans, and this really depends on what human we're speaking about. You have people who are very strict on using braces, and you have people like me who got used to omitting them and got used to reading codes like \bar\theta, \frac12, \frac1n etc.


Mimicking David Carlisle's answer in What does \z@ do? and echoing egreg's comment, the following MWE

\documentclass{article}
\def\a{\setbox0=\hbox{$\frac12\ \bar\theta$}\relax}% No braces
%\def\a{\setbox0=\hbox{$\frac{1}{2}\ \bar{\theta}$}\relax}% Braces
\def\b{\a\a\a\a\a\a\a\a\a\a}%         10
\def\c{\b\b\b\b\b\b\b\b\b\b}%        100
\def\d{\c\c\c\c\c\c\c\c\c\c}%      1,000
\def\e{\d\d\d\d\d\d\d\d\d\d}%     10,000
\def\f{\e\e\e\e\e\e\e\e\e\e}%    100,000
\def\g{\f\f\f\f\f\f\f\f\f\f}%  1,000,000
\def\h{\g\g\g\g\g\g\g\g\g\g}% 10,000,000
\begin{document}
abc \h
\end{document}

compiles without braces in 1m11s and with braces in 1m13s. A minor (perhaps negligible) difference in time. This was on a linux machine with AMD Turion 0.55GHz.


UPDATE: Another test, with 100M instances of \frac12 vs \frac{1}{2} on a newer machine (Intel i5, 3.10GHz, linux) shows typical times 3m42s vs. 3m52s, that's a negligible difference of 100ns per \frac.

Related Question