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
Introduce the revised coding style. #410
Conversation
Other than the comments: lgtm. Adding some justifications would be helpful to reevaluate these guidelines in the future (and would give people an idea when/why to violate them). |
I dislike making random local variables / parameters const (assuming you're not referring to const pointers/references). I have been using Rust lately, which requires 'mut' for mutable variables to assist the reader, since most variables need not be; but in Rust there is no syntactic overhead for immutable ones, while in C++, writing const everywhere is very noisy. And there was recently some debate about removing that from Rust... Either way, the rule should apply to all locals, not just function parameters. |
## Introduction | ||
--- | ||
|
||
This guide is for developers who wish to contribute to the Dolphin Emulator codebase. It will detail how to properly style and format code to fit this project. This guide also offers suggestions on specific functions and other varia that may be used in code. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Just saying, we also have the option of just adding a link to https://wiki.dolphin-emu.org/index.php?title=Coding_Style in this file instead. I'm somewhat unhappy with this being basically github-only, when a big part of our developer documentation resides on wiki.dolphin-emu.org. |
### Headers | ||
- If a header is not necessary in a certain source file, remove it. | ||
- If you find duplicate includes of a certain header, remove it. | ||
- When declaring includes in a source file, make sure they follow the given pattern: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
HANDLE should be instead something like "using HandleRsc = a std::unique_ptr<HANDLE,HandleDeleter>;" in the first place. RAII should be a strong recommendation, a line of code you do not have to write ( the release/delete ) is a line of code that will not bug |
|
||
```c++ | ||
template<class T> | ||
inline void Clamp(T* val, const T& min, const T& max) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
I don't really care what is eventually picked, because everyone has varying opinions...but whatever it is NEEDS to be automatically enforceable by a tool. Preferably by VS' and others' built-in solutions for syntax formatting, or at least by an external tool like clang-format or editorconfig which we can package in the dev process. |
By the way, what's the general opinion on forward declaring things in headers instead of blindly including the declaring header, in order to reduce compilation times? http://stackoverflow.com/questions/9906402/should-one-use-forward-declarations-instead-of-includes-wherever-possible provides a good summary of other reasons. E.g. |
This is +1 from me if this is worded as an advice/recommendation, not as a (Making Dolphin work with IWYU would be great :) ). On Fri, Jun 6, 2014 at 6:22 PM, Tony Wasserka notifications@github.com
Pierre "delroth" Bourdon delroth@gmail.com |
I'll just give this my LGTM for now. There are still some outstanding minor issues, but I think it's good enough in the current state. IMO issues like using some coding style which is tool-friendly can be addressed another time, since they will likely require a mass-convert of the existing code base anyway. |
Squashed all commits thus far into one. |
There's no rule on whether to use |
I don't believe there is, though the de-facto accepted way we usually do I can add this to the style if needed.
|
Yeah, I would say this definitely belongs in the coding style. |
Another thing that was discussed on IRC was how to define type aliases. Do we want the more traditional |
Hmm... I think both should be allowed, since they both do the same thing
|
Yeah, there's probably not much of a point in enforcing usage of a single one of them. |
@neobrain Added formatting for references and pointers (specifically in General) |
So is this OK to merge now? |
- All variables should be lowercase with underscores separating the individual words in the name. | ||
- `int this_variable_name;` | ||
- Please do not use [Hungarian notation](http://en.wikipedia.org/wiki/Hungarian_notation) prefixes with variables. The only exceptions to this are the variable prefixes below. | ||
- Global variables – `g_` |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@lioncash: This comment grants you the permission to merge this pull request whenever you think it is ready. After addressing the remaining comments, click this link to merge. That's the last comment I have. Thanks a lot for spending your time on this! Have you checked that Contributing.md works for GitHub? (I thought it had to be named CONTRIBUTING.md in uppercase, but I can't remember testing the non-uppercase variant). @dolphin-emu-bot allowmerge |
### General | ||
- Try to limit lines of code to a maximum of 100 characters. | ||
- Note that this does not mean you should try and use all 100 characters every time you have the chance. Typically with well formatted code, you normally shouldn't hit a line count of anything over 80 or 90 characters. | ||
- The indentation style we use is tabs for initial indentation and then, if vertical alignment is needed, spaces are to be used. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Introduce the revised coding style.
Opinion time!
I did a general revising of the coding style, since the one on the wiki is quite old. Also this will put it in a file within the repo, which is good because whenever someone makes a pull request it will have a little notification that tells people to make sure that they've read the guidelines (see here for more on that). Having it in the repo will be much easier for potential contributors to see instead of the wiki.
This is the first 'draft' so I strongly encourage people to give me opinions and suggestions on this until we agree upon things.