etoolbox uses \newcommand or \newrobustcmd for all user-level commands (to avoid name clashes I presume). Some commands get empty initial definitions with \newcommand{\<cmd>}{} because their real definition needs an \edef or some other treatment that \newcommand doesn't provide. E.g.
\newrobustcmd gets an empty initial definition because it needs to be defined \protected\def
\newcommand*{\newrobustcmd}{}
\protected\def\newrobustcmd{\@star@or@long\etb@new@command}
and \ifdefmacro is ultimately defined via an \edef
\newcommand{\ifdefmacro}{}
\long\edef\ifdefmacro#1{%
\noexpand\expandafter\noexpand\etb@ifdefmacro
\noexpand\meaning#1\detokenize{macro}:&}
\edef\etb@ifdefmacro{%
\def\noexpand\etb@ifdefmacro##1\detokenize{macro}:##2&}
\etb@ifdefmacro{\notblank{#2}}
\protecting needs a #{ type 'argument' (for lack of a better term)
\newcommand*{\protecting}{}
\def\protecting#{%
\ifx\protect\@typeset@protect
\etb@protecting\@firstofone
\fi
\ifx\protect\@unexpandable@protect
\etb@protecting\etb@unexpandable
\fi
\ifx\protect\noexpand
\etb@protecting\unexpanded
\fi
\ifx\protect\string
\etb@protecting\detokenize
\fi
\relax\@firstofone}
\def\etb@protecting#1#2\relax\@firstofone{\fi#1}
\long\def\etb@unexpandable#1{\unexpanded{\protecting{#1}}}
but many other macros like \ifcsmacro use a \newcommand directly
\newcommand*{\ifcsmacro}[1]{%
\ifcsdef{#1}
{\expandafter\ifdefmacro\csname#1\endcsname}
{\@secondoftwo}}
Internal commands (\etb@...) are usually defined directly with \def/\edef/... and not via \newcommand, because name clashes are not expected there.
\newcommandall. So, this is for consistently checking naming clash taken by\newcommand(which is equivalent to\ifcsnamein the current implementation)? – muzimuzhi Z May 24 '20 at 10:26\ifcsname. I don't quite understand what you mean there. Can you clarify what you meant, please? – moewe May 24 '20 at 10:29\newcommand, it uses\@ifdefinable, which uses\@ifundefined, which uses\ifcsnameto check name clash. So to check name clash, using\newcommandis the same as directly using\ifcsnamebut with better error message. – muzimuzhi Z May 24 '20 at 10:42\ifcsnameis true if the csname has a definition so after\let\fooit is true forfoobut the latex definition treats relax as undefined and also gives errors for any command that stars withendwhether it is defined or not. – David Carlisle May 24 '20 at 10:48\@ifdefinableand saw the logic you said. – muzimuzhi Z May 24 '20 at 11:01