Also, please update the Post-History header, adding the date(s) you
posted the PEP to the mailing lists and/or newsgroups.

And this time I'll remember to attach the file :-)

--
David Goodger <http://python.net/~goodger>
PEP: XXX
Title: Codetags
Version: $Revision$
Last-Modified: $Date$
Author: Micah Elliott <mde at tracos.org>
Status: Draft
Type: Informational
Content-Type: text/x-rst
Created: 27-Jun-2005
Post-History: XXX


Abstract
========

This informational PEP aims to provide guidelines for consistent use
of Codetags, which would enable the construction of standard utilities
to take advantage of the Codetag information, as well as making Python
code more uniform across projects.  Codetags also represent a very
lightweight programming micro-paradigm and become useful for project
managment, documentation, change tracking, and project health
monitoring.  This is submitted as a PEP because I feel its ideas are
Pythonic, although the concepts are not unique to Python programming.
Herein are the definition of Codetags, the philosophy behind them, a
motivation for standardized conventions, a specification, a toolset
description, and possible objections to the Codetag project/paradigm.

This PEP is also living as a wiki_ for people to add comments.


What Are Codetags?
==================

Programmers widely use ad-hoc code comment markup conventions to serve
as reminders of sections of code that need closer inspection or
review.  Examples of markup include ``FIXME``, ``TODO``, ``XXX``,
``BUG``, but there many more in wide use in existing software.  Such
markup will henceforth be referred to as *Codetags*.  These Codetags
may show up in application code, unit tests, scripts, general
documentation, or wherever suitable.


Philosophy
==========

If you subscribe to most of these values, then Codetags will likely be
useful for you.

1. As much information as possible should be contained **inside the
   source code** (application code or unit tests).  This along with
   use of Codetags impedes duplication.  Most documentation can be
   generated from that source code; e.g., by using help2man, man2html,
   docutils, epydoc/pydoc, ctdocgen, etc.

2. Information should be almost **never duplicated** -- it should be
   recorded in a single original format and all other locations should
   be automatically generated from the original, or simply be
   referenced.  This is the *SPOT* rule.

3. Documentation that gets into customers' hands should be
   **auto-generated** from single sources into all other output
   formats.  People want documentation in many forms.  It is thus
   important to have a documentation system that can generate all of
   these.

4. Whenever information is subject to (and suited for) user
   feedback/input (e.g., FAQ, RFC, PEP), it should be contained in a
   **repository** (e.g. a wiki, usenet, or mailing lists).

5. There should not be a dedicated, disjoint **documentation team**
   for any non-huge project.  The developers writing the code know the
   code best, and they should be the ones to describe it.

6. **Plain text** (with non-invasive markup) is the best form of
   writing anything.  All other formats are to be generated from the
   plain text.

7. **Revision control** should be used for almost everything.  And
   modifications should be checked in at least daily.


Motivation
==========

* **Various productivity tools can be built around Codetags.**

  See `Toolset Possibilities`_.

* **Encourages consistency.**

  Historically, a subset of these Codetags has been used informally in
  the majority of source code in existence, whether in Python or in
  other languages.  Tags have been used in an inconsistent manner with
  different spellings, semantics, format, and placement. For example,
  some programmers might include datestamps and/or user identifiers,
  limit to a single line or not, spell the Codetag differently than
  others, etc.

* **Encourages adherence to SPOT/DRY principle.**

  E.g., generating a roadmap dynamically from Codetags instead of
  keeping TODOs in sync with separate roadmap document.

* **Easy to remember.**

  All Codetags must be concise, intuitive, and semantically
  non-overlapping with others.  The format must also be simple.

* **Use not required/imposed.**

  If you don't use Codetags already, there's no obligation to start,
  and no risk of affecting code (but see Objections_).  A small subset
  can be adopted and the Tools_ will still be useful (a few Codetags
  have probably already been adopted on an ad-hoc basis anyway).  Also
  it is very easy to identify and remove if a Codetag is no longer
  deemed useful.  Then it is effectively *committed* and recorded by
  revision control simply by checking in.

* **Gives a global view of code.**

  Tools can be used to generate documentation and reports.

* **A logical location for capturing CRCs/Stories/Requirements.**

  The XP community often does not electronically capture Stories, but
  Codetags seem like a good place to locate them.

* **Extremely lightweight process.**

  Creating tickets in a tracking system for every thought degrades
  development velocity.  Even if a ticketing system is employed,
  Codetags are useful for simply containing links to those tickets.


Examples
========

This shows a simple Codetag as commonly found in sources everywhere
(with the addition of a trailing ``<>``)::

   def foo():
       # FIXME: Seems like this loop should be finite. <>
       while True: ...

The following contrived example demonstrates more a common use of
Codetagging.  It uses some of the available fields to specify the
owners (a pair of developers with initials *mde* and *cle*), the Work
Week of expected completion (*w14*), and the priority of the item
(*p2*)::

   def foo():
       # FIXME: Seems like this loop should be finite. <mde,cle w14 p2>
       while True: ...


Specification
=============

This describes the format: syntax, mnemonic names, fields, and
semantics.


General Syntax
--------------

Each Codetag should be inside a comment, and can be any number of
lines.  It should match the indentation of surrounding code.  The end
of the Codetag is marked by a pair of angle brackets ``<>`` containing
optional fields, which must not be split onto multiple lines.

.. NOTE: This PEP's text originally did not conform to the "inside a
   comment" rule.  Documents can have comments too!  I fixed that.
   -Ed. <DJG 2005-09-14>

There can be multiple fields per Codetag, all of which are optional.

In short, a Codetag consists of a mnemonic, a colon, commentary text,
an opening angle bracket, an optional list fields, and a closing angle
bracket.  E.g., ::

    # MNEMONIC: Some (maybe multi-line) commentary. <field field ...>

.. FIXME: Add completion vs target date?? <mde>


Mnemonics
---------

The Codetags of interest are listed below, using the following format:

| ``recommended mnemonic (& synonym list)``
|     *canonical name*: semantics
|
| Notes

Some of these are temporary (e.g., ``FIXME``) while others are
persistent (e.g., ``REQ``).  Synonyms should probably be deprecated in
the interest of minimalism and consistency.  I chose a mnemonic over a
synonym using three criteria: descriptiveness, length (shorter is
better), commonly used.

``TODO (TBD, MLSTN, DONE)``
   *To Do*: An informal task/feature that is pending completion.
   Relevant to roadmap.

   ``DONE`` is always be a completed ``TODO`` item, but these should
   probably be done through the revision control system.

``FIXME (XXX, DEBUG, BROKEN, RFCTR, OOPS, SMELL)``
   *Fix Me*: Problematic or ugly code.  Needs refactoring or cleanup.

   Choosing between ``FIXME`` and ``XXX`` is difficult.  ``XXX`` seems
   to be more common, but much less descriptive.  Furthermore, ``XXX``
   is a useful placeholder in a piece of code having a value that is
   unknown.  Sun says that ``XXX`` and ``FIXME`` are slightly
   different, giving ``XXX`` higher severity.

   .. TODO: MDE, please add Sun documentation reference <DJG 2005-09-14>

``REQ (STORY)``
   *Requirement*: Satisfaction of a specific, formal requirement.

``RFE (FEETCH, NYI, FR, FTRQ, FTR)``
   *Request For Enhancement*: A roadmap item not yet implemented.

``IDEA``
   *Idea*: Possible ``RFE`` candidate, but less formal than ``RFE``.

``??? (QUEST, WTF, TBD, QSTN)``
   *Question*: A misunderstood (or less-than-fully understood) detail.

   Product of coincidental programming.

   .. ???: what does the above sentence mean? <DJG>

``!!! (ALERT)```
   *Alert*: In need of immediate attention.

   .. NOTE: added on 2005-09-14 <DJG>

``HACK (WKRD)``
   *Hack*: Temporary code to force inflexible functionality, or simply
   a test change, or a workaround of a known problem.

``PORT``
   *Portability*: Workaround specific to an OS, a Python version, etc.

``BUG (BUGFIX)``
   *Bug*: Reported defect tracked in bug database.

``NOTE (HELP)``
   *Note*: Implementation detail that stands out as non-intuitive.  Or
   a code reviewer found something that needs discussion or further
   investigation.

   It may be a useful metric to count ``NOTE`` tags: a high count may
   indicate a problem.

``FAQ``
   *Frequently Asked Question*: Interesting area that requires
   external explanation.

   This is probably more appropriately documented in a wiki where
   users can more easily contribute.

``GLOSS``
   *Glossary*: Item definition for the project glossary.

``STAT``
   *Status*: File-level statistical indicator of work needing done on
   this file.

``RVDBY``
   *Reviewed By*: File-level indicator of programmer(s) who performed
   recent code review.

``SEE (REF)``
   *Reference*: Pointer to other code, web link, etc.

File-level Codetags might be better suited as properties in the
revision control system.


Fields
------

All fields are optional. It should be possible for groups to define or
add their own, but the proposed standard fields are as follows:

``wNN``
    Workweek target completion (estimation).  Origination and
    completion are freebies with revision control.

``pN``
    Priority level.

``xxx[,yyy]...``
    List of initials of owners of completion responsibility.  There
    should be no digits in initials.

    .. ???: should initials be uppercase or lowercase?  I prefer
       uppercase, personally. <DJG 2005-09-14>

``yyyy[-mm[-dd]]``
    The date of the comment, in `ISO 8601`_ format (digits and hyphens
    only).

    .. NOTE: added on 2005-09-14 <DJG>


Toolset Possibilities
=====================

Currently, programmers (and sometimes analysts) typically use *grep*
to generate a list of items corresponding to a single Codetag.
However, various hypothetical productivity tools could take advantage
of a consistent Codetag format.  Some example tools follow.

.. NOTE: Codetag tools are mostly unimplemented (but I'm getting
   started!) <mde>

Document Generator
    Possible docs: glossary, roadmap, manpages

Codetag History
    Track (with revision control system interface) when a ``BUG`` tag
    (or any codetag) originated/resolved in a code section

Code Statistics
    A project Health-O-Meter

Codetag Lint
    Notify of invalid use of Codetags, and aid in porting to Codetag

Story Manager/Browser
    An electronic means to replace XP notecards.  In MVC terms, the
    Codetag is the Model, and the Story Manager could be a graphical
    Viewer/Controller to do visual rearrangment, prioritization, and
    assignment, milestone management.

Any Text Editor
    Used for changing, removing, adding, rearranging Codetags.

There are some tools already in existence that take advantage of a
smaller set of pseudo-Codetags (see References_).


Objections
==========

:Objection: Extreme Programming argues that such Codetags should not
    ever exist in code since the code is the documentation.

:Defense: Maybe put the Codetags in the unit test files instead.
    Besides, it's tough to generate documentation from uncommented
    source code.

----

:Objection: Too much existing code has not followed proposed
    guidelines.

:Defense: [Simple] utilities (*ctlint*) could convert existing codes.

----

:Objection: Causes duplication with tracking system.

:Defense: Not really.  If an item exists in the tracker, a simple
    ticket number as the Codetag commentary is sufficent.  Maybe a
    duplicated title would be acceptable.  Furthermore, it's too
    burdensome to have a ticket filed for every item that pops into a
    developer's mind on-the-go.

----

:Objection: Codetags are ugly and clutter code.

:Defense: That is a good point.  But I'd still rather have such info
    in a single place (the source code) than various other documents,
    likely getting duplicated or forgotten about.

----

:Objection: Codetags (and all comments) get out of date.

:Defense: Not so much if other sources (externally visible
    documentation) depend on them being accurate.


References
==========

Some other tools have approached defining/exploiting Codetags.
See http://tracos.org/codetag/wiki/Links.

.. _wiki: http://tracos.org/codetag/wiki/Pep
.. _ISO 8601: http://en.wikipedia.org/wiki/ISO_8601

..
  Local Variables:
  mode: indented-text
  indent-tabs-mode: nil
  sentence-end-double-space: t
  fill-column: 70
  End:

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to