MoinMoin Coding Style

MoinMoin code has developed over the years (some parts more, some less) and got many contributions from many different people, so coding style in moin is not very homogeneous.

But the goal should be to improve it long-term - and for new code please follow the guidelines below so it doesn't induce boring cleanup work on others:

The long version

We mostly follow PEP 8 coding style (see also Python Idioms).

Especially:

Except:

The short version

Write clean and readable code. If you don't need comments often because your code reads clear, that's great.

That does NOT mean that there should be no docstrings.

Vim Python PEP8 helper

If you are using Vim you can use python.vim - a really nice helper to write great looking code. Install it at ~/.vim/syntax/python.vim.

~/.vimrc

syntax on
set noai
set tabstop=4
set expandtab
set shiftwidth=4
filetype indent on

Automatic PEP8 checker

Since moin/1.7 branch we have an automatic PEP8 checker in MoinMoin/_tests/test_sourcecode.py. It contains a test generator that generates about 3600 tests (one test per file), so you get the checker's stdout per src file if the check for that file fails.

As of 2007-07-03, none of those tests fails. :) Please keep that state by running py.test before committing - and only commit if it has 0 failing tests.

MoinMoin Repository Commit Style

If you work on MoinMoin code and you would like your changesets to be acceptable for the main MoinMoin repositories, you should keep some stuff in mind:

Do commit often

Noone likes to dissect or review huge changesets.

If you work privately for some weeks or months on a new feature and your result is just one or a few changesets, that likely won't get accepted.

Do clean commits

Properties of clean commits are:

A good way to achieve this is to use hg diff and hg st very often, reading your changes again and again, line by line, word by word, thinking about your changes again and again - until you are completely happy with them. Then think about a good commit comment and commit.

Do good commit comments

Properties of good commit comments:

Reading hg diff and hg st output often helps in finding some reasonable commit comment.

MoinMoin: CodingStyle (last edited 2011-03-20 18:37:27 by ThomasWaldmann)