logo_kerberos.gif

Difference between revisions of "Coding style/Transition strategies"

From K5Wiki
Jump to: navigation, search
(New page: == Whitespace == To mark files as having all tabs expanded to space characters, place the following Emacs mode/local-variable line at the very top of the file: <pre> /* -*- mode: c; inde...)
 
(update and add reference to krb5-c-style.el)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
  +
Parts of the existing source tree are not conforming to our coding style. These inconsistencies can create barriers to entry for new contributors. This page outlines some transition strategies.
  +
  +
== Implementation of transition ==
  +
  +
Multiple phases. Consider batching changes.
  +
  +
* Tabs to spaces (and related whitespace issues like end-of-line whitespace)
  +
** Mark with emacs file variables
  +
** Confirm that this worked by checking if "<code>diff -w</code>" shows no changes
  +
* Reindent
  +
** Mark with emacs file variables
  +
** As this may change linebreaks, requires a little more review
  +
  +
== Exempt code ==
  +
  +
Sun-origin code:
  +
* src/lib/rpc
  +
* src/include/gssrpc
  +
  +
BSD-origin code:
  +
* src/appl/bsd
  +
* src/appl/telnet
  +
* src/appl/gssftp
  +
* src/plugins/kdb/db2/libdb2
  +
 
== Whitespace ==
 
== Whitespace ==
   
Line 6: Line 31:
 
/* -*- mode: c; indent-tabs-mode: nil -*- */
 
/* -*- mode: c; indent-tabs-mode: nil -*- */
 
</pre>
 
</pre>
  +
  +
== Indentation ==
  +
  +
To mark files as having indentation conforming to our coding style, add <code>c-basic-offset: 4</code> to the local variable line:
  +
  +
<pre>
  +
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
  +
</pre>
  +
  +
Some emacs customizations for automatically using the "krb5" c style are in {{trunkref|src/util/krb5-c-style.el}}; putting a reference to that style in the local variable line would not be friendly to developers who do not define that style in their <code>.emacs</code> files, so we will use the combination of <code>c-basic-offset</code> and <code>indent-tabs-mode</code> instead.
  +
  +
For BSD-derived code, use
  +
  +
<pre>
  +
/* -*- mode: c; c-file-style: "bsd"; indent-tabs-mode: t -*- */
  +
</pre>
  +
  +
as the "bsd" style is already defined by most implementations of emacs CC Mode.
  +
  +
== Vim? ==
  +
  +
Do we want to add file modelines for vim? Some versions of vim had vulnerabilities in handling of modelines.

Latest revision as of 01:02, 3 November 2009

Parts of the existing source tree are not conforming to our coding style. These inconsistencies can create barriers to entry for new contributors. This page outlines some transition strategies.

Implementation of transition

Multiple phases. Consider batching changes.

  • Tabs to spaces (and related whitespace issues like end-of-line whitespace)
    • Mark with emacs file variables
    • Confirm that this worked by checking if "diff -w" shows no changes
  • Reindent
    • Mark with emacs file variables
    • As this may change linebreaks, requires a little more review

Exempt code

Sun-origin code:

  • src/lib/rpc
  • src/include/gssrpc

BSD-origin code:

  • src/appl/bsd
  • src/appl/telnet
  • src/appl/gssftp
  • src/plugins/kdb/db2/libdb2

Whitespace

To mark files as having all tabs expanded to space characters, place the following Emacs mode/local-variable line at the very top of the file:

/* -*- mode: c; indent-tabs-mode: nil -*- */

Indentation

To mark files as having indentation conforming to our coding style, add c-basic-offset: 4 to the local variable line:

/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */

Some emacs customizations for automatically using the "krb5" c style are in src/util/krb5-c-style.el (raw | annotated | history); putting a reference to that style in the local variable line would not be friendly to developers who do not define that style in their .emacs files, so we will use the combination of c-basic-offset and indent-tabs-mode instead.

For BSD-derived code, use

/* -*- mode: c; c-file-style: "bsd"; indent-tabs-mode: t -*- */

as the "bsd" style is already defined by most implementations of emacs CC Mode.

Vim?

Do we want to add file modelines for vim? Some versions of vim had vulnerabilities in handling of modelines.