Skip to content

Code Style

fosterbarnes edited this page Oct 29, 2026 · 1 revision

How FTB code is written. Match the file you are in; these are the rules behind it.

C (source/core, source/app)

FTB keeps FBI's C style:

Thing Style Example
Functions snake_case, prefixed with the module ciainstaller_open, list_set_layout
Types snake_case, often with a _s struct tag list_item, ftb_settings, task_state
Locals, parameters, fields camelCase populateData, foldersVersion
Macros and constants UPPER_SNAKE_CASE CIA_FOLDERS_MAX, COLOR_TEXT
File names as they are (lowercase, no separators) ciainstaller.c, listtitles.c
  • 4-space indents, if(x) { with no space before the parenthesis, braces on the same line, type* name.
  • Guard clauses and early returns over deep nesting.
  • Tables over long if/else chains: settings (settings_bools, settings_choices), theme files (resources_colors, resources_textures), and services in main.c are all tables.
  • Designated initializers for static items: {.name = "Settings", .color = COLOR_TEXT, .data = ...}.
  • Build text with string_append(out, size, &pos, text), never pos += snprintf(...). A path snprintf whose cut result would touch the wrong file checks its return and fails with R_APP_OUT_OF_RANGE.
  • Zero compiler warnings.

C++ (source/ftpd)

ftpd keeps its own style: tabs, a space before call parentheses, m_ members, name_ parameters. Mark FTB-specific changes with a FTB: comment where they would surprise someone who knows ftpd.

Libraries (source/libs)

quirc and stb_image get real bug fixes and version updates only. Do not restyle them.

Comments

  • Comment why, or how a piece fits with the rest, not what the next line does.
  • Keep comments short and remove them when the code they describe changes.
  • TODO: for work not started.

Text and docs

  • No em dashes anywhere: code, comments, UI strings, docs. Use - or :.
  • UI strings say what something does or what state it is in. No taglines or filler text.
  • Plain English in docs, short sentences.

Names that must never change

  • UNIQUE_ID (0xF8F7B) and PRODUCT_CODE (CTR-P-CFTB) in the Makefile: they keep FTB installable next to FBI, and changing them makes the console treat updates as a different app.
  • romfs/ file names and textcolor.cfg keys: themes override them by name (see Theming). Add new art under new names.
  • Release asset names FTB.cia, FTB.3dsx, FTB.3ds, FTB.zip: the in-app updater looks for them by name.
  • Values stored in settings.cfg: append new enum values, never renumber.

Clone this wiki locally