diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-11-18 10:52:37 +0000 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-11-18 10:52:37 +0000 |
commit | e4d5933e0a81373b7870cf6a9b5b4c28ab9a57df (patch) | |
tree | 01d89db1fbfffb42eb3b9bb4bff902f12dd42e99 /doc | |
parent | 7f5b839524cad9211699c68ea02d11c1758a800b (diff) |
* "with args" considered harmful.
svn path=/nixpkgs/trunk/; revision=18404
Diffstat (limited to 'doc')
-rw-r--r-- | doc/coding-conventions.xml | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/doc/coding-conventions.xml b/doc/coding-conventions.xml index 3e4afdc1d4f5..586fcd98f23d 100644 --- a/doc/coding-conventions.xml +++ b/doc/coding-conventions.xml @@ -156,6 +156,52 @@ stdenv.mkDerivation { ... </para></listitem> + <listitem><para>Functions should list their expected arguments as + precisely as possible. That is, write + +<programlisting> +{ stdenv, fetchurl, perl }: <replaceable>...</replaceable> +</programlisting> + + instead of + +<programlisting> +args: with args; <replaceable>...</replaceable> +</programlisting> + + or + +<programlisting> +{ stdenv, fetchurl, perl, ... }: <replaceable>...</replaceable> +</programlisting> + + </para> + + <para>For functions that are truly generic in the number of + arguments (such as wrappers around <varname>mkDerivation</varname>) + that have some required arguments, you should write them using an + <literal>@</literal>-pattern: + +<programlisting> +{ stdenv, doCoverageAnalysis ? false, ... } @ args: + +stdenv.mkDerivation (args // { + <replaceable>...</replaceable> if doCoverageAnalysis then "bla" else "" <replaceable>...</replaceable> +}) +</programlisting> + + instead of + +<programlisting> +args: + +args.stdenv.mkDerivation (args // { + <replaceable>...</replaceable> if args ? doCoverageAnalysis && args.doCoverageAnalysis then "bla" else "" <replaceable>...</replaceable> +}) +</programlisting> + + </para></listitem> + </itemizedlist> </section> |