I have a question about the many ways to define a new command. I looked through the web and TeX.SE but couldn't find a complete answer (only some partly answers like, here, here, here, or here).
I know of several ways:
\newcommand,\DeclareRobustCommand,\newrobustcmd,\NewDocumentCommand,\NewExpandableDocumentCommand
to name just a few, most of them also with starred versions, and of course the primitives like
\def,\gdef,\edefand so on.
I have come to the conclusion that it is usually better to use LaTeX macros to define new commands, rather than using primitives. Some arguments pro macros are better syntax (allowing you to understand the execution), security (since most macros check for existing command-names), or the possibility to patch or redefine the commands.
But when I skimmed through several other cls files by third parties, I found that they very often use the \def primitives over the elaborated macros. The latter are more or less only used in special situations.
Are there valid reasons to use primitives over LaTeX macros to define new commands; especially when writing a cls file? Maybe reduce package size, or something similar? Or just old habits?
I know that it will depend on the situation, if I simply use \newcommand or \newrobustcmd. But maybe there is a strong tendency, when to use primitives in class files rather than macros?
Edit
As suggested in my question and confirmed in the comments there is no general answer. Therefore, it would be great if some of the more experienced LaTeX authors could share their personal preferences when writing/editing a class file, and why they do it this way.
Edit 2
What I forgot so far are the expl3 commands like \cs_new.... If I understood it correctly, LaTeX3 was introduced as elaborated programming layer especially for usage in sty, cls and other backend files. So, would/should a modern approach in writing such files relay more on these expl3 commands than on primitives or more or less simple LaTeX macros?
\@ifdefinable. – Skillmon Jul 14 '23 at 15:41\defis used very often, also for very simple definitions like\def\command{short definition}. That's one of the points why I ask if there is a reason for that frequent use of it. But maybe its all due to my little experience working in the Latex backend... – lukeflo Jul 14 '23 at 15:51\defcould be that if you know what are really you doing , why the hell should you deprive yourself of using\defto use, for example,\newcommand\foo{}, and check if the command was already defined , when that doesn't matter to you? – Fran Jul 15 '23 at 02:11expl3versions) over primitives for class (or package) writing. – lukeflo Jul 15 '23 at 13:36