This file describes the C++ and Ruby code styles in this repository. If you are looking for instructions on how to customize and compile Gosu, see the Hacking Gosu wiki page.
Do not use lines longer than 100 characters, except in Markdown files, where each line should be one sentence.
Rationale: Shorter lines introduce distracting line breaks.
Longer lines require horizontal scrolling in editors (depending on screen size) and on GitHub.
Gosu provides a .clang-format file that yields acceptable results for most C++ code.
Sometimes, code will look a bit more consistent if you add a //
at the end of a line to force a line break.
- Use the
rufo
gem with the default settings. Visual Studio Code has a plugin to format code on save. - Use simple (dumb, boring) Ruby code where possible.
Rationale: Ruby/Gosu is often used by novices. - Use
"
for strings, only use'
when absolutely necessary. Rationale: Consistency. - Do not replace all uses of
if not
byunless
. There is a time and place for both.
Rationale: The English word "unless" is used to describe exceptional conditions.
See also this discussion on GitHub. - Use
and
,or
andnot
in conditions. Example:if admin? and not undeletable?
Example:while object = stack.pop and object.valid?
Rationale: Easy to read, consistency with other control flow operators. - Use
&&
,||
and!
in Boolean algebra.
Example:should_delete = is_admin && !is_undeletable
Example:puts(description || "no description")
Rationale: Consistency with other binary operators (|
/&
and||=
/&&=
), no problems with operator precedence.