# Differences in LaTeX3 function generation methods

In l3basics module there are two methods provided for each command generating function. The one requires the function signature to be provided, whereas the second does not.

Since the second is more concise, are there any advantages of using the one rather than the other? (Except of course in the obvious case where one needs to remove one token completely, such as a hypothetical \removefirstoftwo case etc and the second method cannot be applied).

I provide a MWE illustrating the two approaches.

\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn
\cs_new:Npn \exampleone:nn #1 #2 {#1 #2}
\cs_new:Nn \exampletwo:nn{#1 #2}
\exampleone:nn {one~}{two~}
\exampletwo:nn {three~}{four}
\ExplSyntaxOff
\end{document}

• It's exactly the same; the former method is slightly faster to process. – egreg Apr 26 '15 at 15:02
• @egreg Thanks, but I am curious why it was necessary to provide both, there must be some reasoning behind it. – Yiannis Lazarides Apr 26 '15 at 15:04

The two methods are perfectly equivalent, when a signature is added to the function being defined.

The \cs_new:Nn method is less efficient, as it has to build the parameter text.

\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn
\cs_new:Npn \exampleone:nn #1 #2 {#1 #2}
\cs_new:Nn \exampletwo:nn{#1 #2}

\texttt{\cs_meaning:N \exampleone:nn}\par

\texttt{\cs_meaning:N \exampletwo:nn}\par

\ExplSyntaxOff
\end{document}


Conciseness of the latter method may make one prefer it, but it's essentially a question of personal preference.

Generally I prefer seeing the explicit parameter text, but that's me.

Why are they both offered? Probably because the :Nn method is similar to the traditional \newcommand, where the parameter text is built from the optional argument, here substituted by the signature of the macro being defined.

Caveat. One can define a function without a signature, but in this case the :Npn method is mandatory. The same if the signature is not “standard”, that is with only N, n, T or F specifiers. A function with a w specifier must use :Npn.