Skip to content

FBReaderJ coding style guide

llfer2006 edited this page Jul 24, 2012 · 7 revisions
  • Naming convention

    • All the classes, interfaces, methods and variables should be named in CamelCaseStyle.
    • All the constant (i.e. public static final fields) names should be written in upper case, with '_' as a word separator.
    • We prefer to use complete English words in names: doSomething() is much better than doSmth() or sdelatNechto().
    • Class and interface names should be started from an upper-case character, methods, fields and variables should be started from a lower-case character.
    • All the (non-static) field names should have prefix 'my'. (We omit this prefix and start a field name with an upper-case character for public final fields; see below.)
    • All the static (non-constant) field names have prefix 'our'.
  • Formatting

    • We use tabs for indenting. In our editors a tab is visible as 4 spaces.
    • We place all the opening brackets ( { ) on the same line where the corresponding control structure is located.
  • Other rules

    • We prefer to make class fields final if it is possible.
    • For final fields, we prefer to make the field public instead of creating a getter. For such fields we do not use prefix 'my'; we start such name with an upper-case character.
    • If something in an existing code is not implemented at this moment, we insert a TODO-marked comment.
    • By historical reasons we do not use enums; please use a set of integer constants instead.
    • We prefer to write class members in the following order:
      • constants
      • static fields
      • static methods
      • fields
      • constructors
      • methods
  • A sample

class Book {
    public static final int BOOK_FORMAT_EPUB = 0;
    public static final int BOOK_FORMAT_FB2 = 1;

    private static ourCounter = 0;

    public static getCounter() {
        return ourCounter;
    }

    public final String Title;
    private int myCurrentPageNumber;

    public Book(String title, int currentPageNumber) {
        ++ourCounter;
        Title = title;
        myCurrentPageNumber = currentPageNumber;
    }

    public Book(String title) {
        this(title, 0);
    }

    public int getCurrentPageNumber() {
        return myCurrentPageNumber;
    }

    public void gotoNextPage() {
        // TODO: check if we are already at the last page; do nothing in such case
        ++myCurrentPageNumber;
        // TODO: update the view
    }

    public void gotoPreviousPage() {
        if (myCurrentPageNumber == 0) {
            return;
        }
        // TODO: implement
    }
}