The rules this code is written by.
- English in the code: identifiers, comments, docstrings, UI text.
- PEP 8: 4 spaces, lines up to 100 columns,
lower_case_with_underscoresfor functions and variables,CapWordsfor classes,UPPER_CASEfor module constants. - Object-oriented: the logic lives in classes, one responsibility each, and one class per module, named after it. Tests may keep their small stand-ins beside them.
- Böhm–Jacopini: only sequence,
if, loops and assignments. One exit per function: noreturnin the middle, nobreak/continue. A function that needs several exits is doing several things and must be split.raiseis allowed, for real errors only. - One thing per line: a plain
if/else, neverx if condition else y. - DRY: every piece of knowledge is written once. Two copies start identical, one gets fixed
and the other does not: a list or a form repeated goes to a base class, a helper used twice
goes to
ToolsorDBMS. - KISS and YAGNI: the simplest solution that still reads clearly in two years; nothing written for an imagined future.
- Least surprise: a name promises what the code does, no more. A
get_*returns and writes nothing, no hidden side effects. Windows that do similar things behave the same way. - Fail fast, fail safe, never silently: on error stop near the cause and leave the database consistent (rollback). A failed read must not look like "no rows".
- By hand where it teaches: where a library is not really needed, a small class written by
hand shows what it does underneath (
Log,Config,Events), and its docstring names the library it stands in for.
- File header block with
project: Tkinterlite,authors: Giuseppe Costanzi (1966bc),licence: GPL-3.0-or-later, see LICENSE. No modification date: git keeps it per file. The release date, Latin season + Roman year (e.g.hiems MMXXI), lives once, in__date__next to__version__inui/app.py. - Widget prefixes (Hungarian notation?):
lst_,cb_,txt_,lbl_,frm_,btn_,ent_,chk_. - Widgets used often are built by
Tools:get_tree,get_listbox,get_combo(readonly),get_entry(text, integer, float),get_text. Buttons come fromget_button_column, given(label, command)pairs: it underlines the first free letter and binds it to Alt. - A list window is a
ui.base.ListWindow, a one-row form is aui.base.Dialog. - ttk styles (
App.*,StatusBar.TLabel, ...) are all defined inTools.set_style(). .format()strings.- Confirmations through
messagebox, with the texts held by the engine (ask_to_save,ask_to_delete,abort,no_selected).