<commit_before><chapter xmlns="http://docbook.org/ns/docbook"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xml:id="chap-conventions">

<title>Coding conventions</title>


<section><title>Syntax</title>

<itemizedlist>

  <listitem><para>Use 2 spaces of indentation per indentation level in
  Nix expressions, 4 spaces in shell scripts.</para></listitem>

  <listitem><para>Do not use tab characters, i.e. configure your
  editor to use soft tabs.  For instance, use <literal>(setq-default
  indent-tabs-mode nil)</literal> in Emacs.  Everybody has different
  tab settings so it’s asking for trouble.</para></listitem>

  <listitem><para>Use <literal>lowerCamelCase</literal> for variable
  names, not <literal>UpperCamelCase</literal>.  TODO: naming of
  attributes in
  <filename>all-packages.nix</filename>?</para></listitem>

  <listitem><para>Function calls with attribute set arguments are
  written as

<programlisting>
foo {
  arg = ...;
}
</programlisting>

  not

<programlisting>
foo
{
  arg = ...;
}
</programlisting>

  Also fine is

<programlisting>
foo { arg = ...; }
</programlisting>

  if it's a short call.</para></listitem>

  <listitem><para>In attribute sets or lists that span multiple lines,
  the attribute names or list elements should be aligned:

<programlisting>
# A long list.
list =
  [ elem1
    elem2
    elem3
  ];

# A long attribute set.
attrs =
  { attr1 = short_expr;
    attr2 =
      if true then big_expr else big_expr;
  };

# Alternatively:
attrs = {
  attr1 = short_expr;
  attr2 =
    if true then big_expr else big_expr;
};
</programlisting>

  </para></listitem>

  <listitem><para>Short lists or attribute sets can be written on one
  line:

<programlisting>
# A short list.
list = [ elem1 elem2 elem3 ];

# A short set.
attrs = { x = 1280; y = 1024; };
</programlisting>

  </para></listitem>

  <listitem><para>Breaking in the middle of a function argument can
  give hard-to-read code, like

<programlisting>
someFunction { x = 1280;
  y = 1024; } otherArg
  yetAnotherArg
</programlisting>

  (especially if the argument is very large, spanning multiple
  lines).</para>

  <para>Better:

<programlisting>
someFunction
  { x = 1280; y = 1024; }
  otherArg
  yetAnotherArg
</programlisting>

  or

<programlisting>
let res = { x = 1280; y = 1024; };
in someFunction res otherArg yetAnotherArg
</programlisting>

  </para></listitem>

  <listitem><para>The bodies of functions, asserts, and withs are not
  indented to prevent a lot of superfluous indentation levels, i.e.

<programlisting>
{ arg1, arg2 }:
assert system == "i686-linux";
stdenv.mkDerivation { ...
</programlisting>

  not

<programlisting>
{ arg1, arg2 }:
  assert system == "i686-linux";
    stdenv.mkDerivation { ...
</programlisting>

  </para></listitem>

  <listitem><para>Function formal arguments are written as:

<programlisting>
{ arg1, arg2, arg3 }:
</programlisting>

  but if they don't fit on one line they're written as:

<programlisting>
{ arg1, arg2, arg3
, arg4, ...
, # Some comment...
  argN
}:
</programlisting>

  </para></listitem>

</itemizedlist>

</section>


<section><title>File naming and organisation</title>

<para>Names of files and directories should be in lowercase, with
dashes between words — not in camel case.  For instance, it should be
<filename>all-packages.nix</filename>, not
<filename>allPackages.nix</filename> or
<filename>AllPackages.nix</filename>.</para>

</section>


</chapter><commit_msg>* "with args" considered harmful.<commit_after><chapter xmlns="http://docbook.org/ns/docbook"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xml:id="chap-conventions">

<title>Coding conventions</title>


<section><title>Syntax</title>

<itemizedlist>

  <listitem><para>Use 2 spaces of indentation per indentation level in
  Nix expressions, 4 spaces in shell scripts.</para></listitem>

  <listitem><para>Do not use tab characters, i.e. configure your
  editor to use soft tabs.  For instance, use <literal>(setq-default
  indent-tabs-mode nil)</literal> in Emacs.  Everybody has different
  tab settings so it’s asking for trouble.</para></listitem>

  <listitem><para>Use <literal>lowerCamelCase</literal> for variable
  names, not <literal>UpperCamelCase</literal>.  TODO: naming of
  attributes in
  <filename>all-packages.nix</filename>?</para></listitem>

  <listitem><para>Function calls with attribute set arguments are
  written as

<programlisting>
foo {
  arg = ...;
}
</programlisting>

  not

<programlisting>
foo
{
  arg = ...;
}
</programlisting>

  Also fine is

<programlisting>
foo { arg = ...; }
</programlisting>

  if it's a short call.</para></listitem>

  <listitem><para>In attribute sets or lists that span multiple lines,
  the attribute names or list elements should be aligned:

<programlisting>
# A long list.
list =
  [ elem1
    elem2
    elem3
  ];

# A long attribute set.
attrs =
  { attr1 = short_expr;
    attr2 =
      if true then big_expr else big_expr;
  };

# Alternatively:
attrs = {
  attr1 = short_expr;
  attr2 =
    if true then big_expr else big_expr;
};
</programlisting>

  </para></listitem>

  <listitem><para>Short lists or attribute sets can be written on one
  line:

<programlisting>
# A short list.
list = [ elem1 elem2 elem3 ];

# A short set.
attrs = { x = 1280; y = 1024; };
</programlisting>

  </para></listitem>

  <listitem><para>Breaking in the middle of a function argument can
  give hard-to-read code, like

<programlisting>
someFunction { x = 1280;
  y = 1024; } otherArg
  yetAnotherArg
</programlisting>

  (especially if the argument is very large, spanning multiple
  lines).</para>

  <para>Better:

<programlisting>
someFunction
  { x = 1280; y = 1024; }
  otherArg
  yetAnotherArg
</programlisting>

  or

<programlisting>
let res = { x = 1280; y = 1024; };
in someFunction res otherArg yetAnotherArg
</programlisting>

  </para></listitem>

  <listitem><para>The bodies of functions, asserts, and withs are not
  indented to prevent a lot of superfluous indentation levels, i.e.

<programlisting>
{ arg1, arg2 }:
assert system == "i686-linux";
stdenv.mkDerivation { ...
</programlisting>

  not

<programlisting>
{ arg1, arg2 }:
  assert system == "i686-linux";
    stdenv.mkDerivation { ...
</programlisting>

  </para></listitem>

  <listitem><para>Function formal arguments are written as:

<programlisting>
{ arg1, arg2, arg3 }:
</programlisting>

  but if they don't fit on one line they're written as:

<programlisting>
{ arg1, arg2, arg3
, arg4, ...
, # Some comment...
  argN
}:
</programlisting>

  </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 &amp;&amp; args.doCoverageAnalysis then "bla" else "" <replaceable>...</replaceable>
})
</programlisting>

  </para></listitem>

</itemizedlist>

</section>


<section><title>File naming and organisation</title>

<para>Names of files and directories should be in lowercase, with
dashes between words — not in camel case.  For instance, it should be
<filename>all-packages.nix</filename>, not
<filename>allPackages.nix</filename> or
<filename>AllPackages.nix</filename>.</para>

</section>


</chapter>
{'fraction_non_alphanumeric': 0.13090102304942686, 'fraction_numerical': 0.016270183655860963, 'mean_word_length': 3.9027190332326285, 'pattern_counts': {'":': 0, '<': 221, '<?xml version=': 0, '>': 221, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2329570', 'n_tokens_mistral': 2841, 'n_tokens_neox': 2601, 'n_words': 783}