By reading the contents of the file book.cls (the standard book class for LaTeX), I can see there are many uses of \def and \newcommand. What I don't seem to understand is why one is used in some cases and why the other in other cases. I couldn't find a pattern.
I understand the differences between\def and \newcommand, and I am aware that I should prefer the latter in everyday document writing. However, my question goes on the context of class and package development. For example, I could define a \title command for my new book class, that also accepts a subtitle as optional argument, by writing
\def\doc@title{}
\def\doc@subtitle{}
\def\title{\kernel@ifnextchar[{\@@title}{\@title}%
\def\@title#1{
\@@title[]{#1}%
}
\def\@@title[#1]#2{%
\gdef\doc@subtitle{#1}
\gdef\doc@title{#2}
}
However, I could also say
\newcommand\doc@title{}
\newcommand\doc@subtitle{}
\newcommand{\title}[2][]{
\gdef\doc@subtitle{#1}
\gdef\doc@title{#2}
}
Is there any reason to prefer one way over the other in the previous pieces of code?
Similarly, the book.cls file has this line:
\DeclareOption{10pt}{\renewcommand\@ptsize{0}}
Why is it not written as
\DeclareOption{10pt}{\def\@ptsize{0}}
In class/package development, what are the criteria to use \newcommand in some situation and \def in other?
