Skip to content

Code style guide#300

Draft
jperon wants to merge 2 commits into
masterfrom
jperon_codestyle
Draft

Code style guide#300
jperon wants to merge 2 commits into
masterfrom
jperon_codestyle

Conversation

@jperon
Copy link
Copy Markdown
Collaborator

@jperon jperon commented Jul 8, 2025

Following a discussion with @lneto, here is a proposal for a coding style guide. Submitting as a draft, as it’s open to criticism and modifications!

Comment thread Codestyle.md Outdated
@jperon jperon mentioned this pull request Jul 9, 2025
2 tasks
Comment thread Codestyle.md

## Line breaks, new lines and file Endings

All source files must end with two empty lines. Otherwise, there mustn’t be multiple consecutive empty lines in the files.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one, right.. one empty line at the end of the file

Comment thread Codestyle.md

## Line Breaking

Staying under 80 characters per line is [preferred](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=bdc48fa11e46f867ea4d75fa59ee87a7f48be144), but [don’t stick to this rule against common sense](https://lkml.org/lkml/2020/5/29/1038).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually don't respect this.. we can agree on a sane number though.. 80 is too little

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the reference above, Linus raised the detected limit in the warning script to 100.
Luacheck by default checks for lines > 120.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should see what's the longest in the current code base?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh that's long.. hehe.. any chance of getting the second longest? I think that might be a good number..

Copy link
Copy Markdown
Collaborator Author

@jperon jperon Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

176, then 135.
Over 105903 lines whose length > 9, only 58 (lines of code, not comments or LDoc) are above 100, only 11 above 120.
With Linus leaving a warning above 100, I think it could be a good rule, as soon as we agree that common sense keeps all its rights.

IMHO, this style of break (as function definitions are likely the longest ones) would be the best: two tabs before the second line, to avoid confusion with function body. Python follows this convention. Aligning with the opening parenthesis would require mixing tabs and spaces for indentation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say 120 and 1 tab.. my vote, at least ;-)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could agree on that, then:

Staying under 120 characters per line is _preferred_, but [don’t stick to this rule against common sense](https://lkml.org/lkml/2020/5/29/1038).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants