6

When writing a package, should one use the top-to-bottom approach or bottom-to-top?

For example, the following two methods (in expl3 syntax)

% Top-to-bottom
\NewDocumentCommand \foo {m} { \mytest_foo:n {#1} }
\cs_new:Npn \mytest_foo:n #1 { \__mytest_foo_aux:n {#1} }
\cs_new:Npn \__mytest_foo_aux:n #1 { some~ code~ of~ #1 }

and

% Bottom-to-top
\cs_new:Npn \__mytest_foo_aux:n #1 { some~ code~ of~ #1 }
\cs_new:Npn \mytest_foo:n #1 { \__mytest_foo_aux:n {#1} }
\NewDocumentCommand \foo {m} { \mytest_foo:n {#1} }

Which one is better?

  • 2
    IMHO the one you like and understand better. – Skillmon Aug 19 '17 at 6:12
  • 1
    I agree with Skillmon. Just don't mix it. – TeXnician Aug 19 '17 at 7:21
6

Well really it makes no difference

\cs_new:Npn \mytest_foo:n #1 { \__mytest_foo_aux:n {#1} }
\NewDocumentCommand \foo {m} { \mytest_foo:n {#1} }
\cs_new:Npn \__mytest_foo_aux:n #1 { some~ code~ of~ #1 }

works as well.

For larger projects one may find the "implementation" (using expl3 conventions) in a different file than the "user interface specification" (using xparse) so the order of loading may vary by document even if the code is unchanged.

xparse is designed around the idea of specifying one or more LaTeX2e-style interfaces over some underlying implemented functionality, so whether you put the specification before the implementation depends mostly on how you want to document things, although the documentation doesn't necessarily need to follow the code. You may have written the lower level expl3 code before adding the xparse interface, or you may spec out a user interface using xparse and then later implement something to support it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.