Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style #411

Open
StanHash opened this issue Jul 10, 2023 · 5 comments
Open

Style #411

StanHash opened this issue Jul 10, 2023 · 5 comments

Comments

@StanHash
Copy link
Member

Right now, style is inconsistent (I am to blame too). Here are some examples of diverging style elements found in fe8u:

file author/year braces pointer declaration switch blocks indent
hardware.c camthesaxman/2018 Allman type *var no
ap.c myself/2018 Java type* var no
animedrv.c myself/2019 Allman type* var no
mapanim.c (first half) NoahNelson/2021 Java type *var no
banim-main.c MokhaLeee/2023 K&R ("Linux Kernel") type *var no
prep_itemscreen.c Eebit/2023 Java type* var yes

We should probably agree on a consistent style (at least for braces and pointer declarations I think) and enforce it for contributions. The discussion of which style is, in my opinion, up to regular contributors (right now I think @MokhaLeee and @Eebit qualify).

My own (current) opinions regarding brace and pointer decl style are (sorry Mokha): I don't like K&R braces (inconsistent) and I don't like type *var style declarations (I prefer type * var and mind type* var less). Feel free to disregard them (I only rarely contribute directly these days).

Naming conventions are also something that probably should be made explicit.

@CT075
Copy link
Member

CT075 commented Jul 10, 2023

I am personally of the opinion that the path of least resistance (both in terms of getting consensus and also logistically) is to use an automated formatter, like clang-format. This won't fix things like the occasionally CamelCase slip-up, but it

  • Can be checked automatically on commit, instead of needing to be examined by hand
  • Importantly, it is easy to retroactively apply such a styler to the existing codebase

As for the choice of which styler in particular to use (and indeed whether to listen to me at all -- I barely contribute, maybe you all enjoy arguing about bracket placement and type *var vs type* var), I would recommend picking something with presets. Twiddling the individual options is just more argument fodder.

@StanHash
Copy link
Member Author

I have experimented with clang-format before for decomp (and indeed use it in mgfembp) and it works good for actual code but it (understandably) sucks for weird data initializers whose structure isn't reflected syntactically like procs or sprites. My "solution" was to manually enclose them in // clang-format off blocks.

@MokhaLeee
Copy link
Contributor

But whatever, I don't particularly mind what kind of code style we adopt. If there is consensus, I may also follow to it.

@Eebit
Copy link
Contributor

Eebit commented Jul 11, 2023

I think I would be happy with the formatting options that are already set up for mgfembp -- they seem sensible enough to me. :)

@MokhaLeee
Copy link
Contributor

MokhaLeee commented Sep 7, 2024

Hello guys, I wonder is there a clang format templete for this style? I'm considering write a clang format (not for decomp), for now I have made on:

Language: Cpp
IndentWidth: 4
PointerAlignment: Middle
BreakBeforeBraces: Allman
AccessModifierOffset: -4
IndentCaseLabels: true
Cpp11BracedListStyle: false
SpaceBeforeCpp11BracedList: true
AlignAfterOpenBracket: AlwaysBreak
AllowShortFunctionsOnASingleLine: None
AlignOperands: DontAlign
ColumnLimit: 120
UseTab: Never
SortIncludes: false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants