Skip to content

Developer: Coding guidelines

primalmotion edited this page Aug 19, 2011 · 1 revision

This page describes the way we code for Archipel. In order to avoid to make code weird sometimes, please follow the these guidelines.

Cappuccino Coding Guidelines

The client is written in Cappuccino. We mainly follow the Cappuccino Coding Guidelines. So you must read it.

We only differ on the following points:

  • We use underscored instance variables names, even if we are not working on the Cappuccino Framework itself.
  • We sort alphabetically the instance variables according to differents groups (see below)
  • We do not use underscored variables names for outlets.
  • We use explicit variables names (same as in Cappuccino, but so important)!
  • We DO NOT use tabs. Use 4 spaces indentation
  • We align values when declaring several variables (see below)
  • We alphabetically sort imports and we first import <Frameworks/Stuff.j> then "ourstuff.j"
  • All your code must successfully pass the capp_lint tests
  • Only one class per file

Good Idea

@import <AppKit/Appkit.j>
@import <StropheCappuccino/StropheCappuccino.j>

@import "mystuff.j"

@implementation MyAwesomeAwesomenessController : CPObject
{
    @outlet CPTextField textFieldName;
    @outlet CPView      viewAwesomeStuff;

    CPArray             _arrayOfThings      @accessors(getter=arrayOfThings);
    CPString            _name               @accessors(property=name);

    CPNumber            _numberOfThings;
    CPString            _bar;
    CPString            _foo;
}

- (void)performAwesomeness:(CPString)aParameter
{
    var spam = @"spam",
        egg  = @"egg";
    // do stuff
    return something;
}
@end

Bad Idea

@import <StropheCappuccino/StropheCappuccino.j>
@import "mystuff.j"
@import <AppKit/Appkit.j>

@implementation my_awesome_awesomeness_controller: CPObject {
    @outlet CPTextField textfieldname;
    CPString b;
    CPString f;
    @outlet CPView viewAwesomeStuff;
    CPArray arrayOfThings @accessors();
    CPString name @accessors();
    CPNumber nums;
}

- (void)perform_awesomeness:(CPString)p {
    var spam = @"spam";
    var egg  = @"egg";
    var i, j, k;
    // do stuff
    return s
}

Python Coding Guidelines

We are more flexible with the coding style of archipel agent and modules. The golden rule is you must pass pyflakes test.

  • We follow PEP8
  • We use explicit variables names
  • We align values when declaring multiple variables (not conform to PEP8, you can ignore these warnings)
  • We remove all trailing spaces (TextMate users make sure you have Uber Glory installed)
  • We sort alphabetically imports in following order:
    • pure python packages
    • archipelcore
    • local packages
  • We DO NOT use from package import *

You can use the PEP8 bundle for TextMate to parse your code

Good Idea

import md5
import os
import sys

from archipelcore.pubsub import TNArchipelPubSub
from archipelcore.utils import log, build_iq_error, build_message_error

import mylocalpackage

AWESOME_SUPER_GLOBAL         = 1
ANOTHER_AWESOME_SUPER_GLOBAL = 2

class MyClass (object):
"""
description of the class
"""

def __init__(self, parameter1, parameter2):
    """
    initialize MyClass
    @type parameter1: object
    @param parameter1: the first parameter
    @type parameter2: object
    @param parameter2: the second parameter
    """
    self.spam = "spam"
    self.egg  = "egg"
    
    if parameter1:
        self.foo = parameter1
    
    if parameter2: 
        self.bar = parameter2
        self.do_something()

Bad Idea

import mylocalpackage
import md5
from archipelcore.pubsub import TNArchipelPubSub
from archipelcore.utils import log, build_iq_error, build_message_error
import sys
import os

awesomesuperglobalA = 1
another_awesome_super_globalA = 1

class MyClass( object ):
"""description of the class"""
def __init__( self,parameter1,parameter2 ) :
    self.s="spam"
    self.e="egg"        
    if parameter1 :self.foo=parameter1
    if parameter2 : 
        self.b = parameter2
        self.doSomething ()
Clone this wiki locally