-
-
Notifications
You must be signed in to change notification settings - Fork 359
Create a .editorconfig file #59
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
Conversation
The reason "C and C++" is not yet checked in the list above is that not all of the C and C++ code in the repository uses the same indentation style. We should probably agree on one and modify the code so that it's consistent across the entire project. |
I think C and C++ should be separated. |
So, I think there has been a huge discussion on this in Issue #18 for C++ I am not sure about the other languages. |
I would like another C or C++ programmer to get in on this and confirm that this change would make sense. I just thought that the two were syntactically so similar that it would be logical to use the same indentation method for both. |
@Butt4cak3 it very much makes sense that C and C++ are different. They are very, very different languages, and are written very differently. |
It's also good to point out that I haven't been using stroustrup style at all in the C++ code that I've written. I've moved back towards my own personal style. I can fix this, but if we actually want an editor config, it makes sense to use something similar to LLVM's style (because clang-format works very well on LLVM style). |
To be fair, it is ultimately my job to maintain the style guidelines of the Algorithm Archive. I will be better about that in the future. I think leaving the PR's out for a bit for code reviews is a good step in the right direction. |
I think that switching wholesale to LLVM style is the best way forward for C++ - this makes it incredibly easy to fix, and to format, and we don't really need to worry about anything - just run clang-format. If we want to edit it slightly, I might do
|
Here's a comparison between a few different styles: https://github.com/motine/cppstylelineup |
https://gist.github.com/ubsan/32aa3b4e88f832fd436349bc33eb2b59 for examples of the styles. |
It doesn't look like .editorconfig is really supported by the rust and C++ communities, and I assume also for the Go community; it seems reasonable, for the languages with standard formatters, to use them instead of .editorconfig. For Rust, I think we should probably use straight rustfmt. For Go, I don't think there's really any options? And for C++, I'd recommend the .clang-format I talked about in my comment above. edit: this is also true of ocaml, with ocamlformat. |
@ubsan @leios @Gathros I'd like to ask you to move the discussion about general formatting to other places to leave room for other suggestions here. EditorConfig is only concerned with the type (tab/space) and width of indentation at the start of lines, not bracket placement and other whitespace (with the exception of trailing whitespace at the ends of lines). I will split C and C++ up into two sections. I will leave them both at 4 spaces indentation until someone suggests something else.
I agree that we should use standard formatters for languages that have those, but EditorConfig serves a different purpose. Whether you let a program fix your formatting or not, your editor should still treat the tab key correctly to make it more convenient to view and edit the code. Edit: In case of standard formatters with editor integration that could replace the functionality of EditorConfig, you should obviously use those instead. |
Well then, the default for C++ should be two spaces. Four spaces in C++ is a rarity, ime, and major projects like LLVM, Chromium, and Firefox use 2-space. |
Alright. Thank you very much, @ubsan! C and C++ are now split up and I changed the C++ section to 2 space indentation. By the way, I made an edit to my previous comment. Just making sure that you got that, because I think I made it shortly before you posted your last answer. |
@Butt4cak3 You commited with a user different from your GH one. Was it intentional? |
@Gustorn
I'll add a section for *.go files with tab indention, then.
I rarely see JavaScript code with 2 space indentations. I don't think one can say that there is one single style for JavaScript that's commonly accepted. All the JS contribution in the AAA as of now use 4 spaces. I think I'll leave it like that. When it comes to Markdown, I think going for 2 spaces is reasonable. I was just not sure, so I left it empty for the time being. I'll fill it in.
That's why I've set its indentation to 4 spaces.
No, it was not. I made these changes on another computer and forgot to change my user information. It will be fine after the next rebase, I guess. |
@Butt4cak3 Google, Mozilla, node.js, and npm are all examples of major JS projects/companies that use 2-space. I notice that webpack uses 4-space, but I definitely think that the majority of "major" JS projects are in 2-space. |
@ubsan You're right. Those major projects use 2 space indentation. I still have the impression that most people outside of those prefer 4 spaces. I can definitely see the case for 2 spaces, though. I looked at a few style guides and their popularity and came to the conclusion that it's probably not a bad idea to adopt the 2 space indentation for this project. I'm sure @Gathros will have something to say about this as well. |
@Butt4cak3 No I have nothing to say about that nor any opinion. I do prefer 4 spaces since things are clearer but I don't mind. |
@Butt4cak3 I see you changed it already but a few more projects to support the 2 spaces argument for JS:
|
What I could find for Clojure is that 2 space indentation is the most common and that's what the code submissions in the AAA use. One of them uses a mix of tabs and spaces which is likely unintended. I don't know Clojure at all, so I won't touch the code, but maybe @earthfail can take a look at it since he submitted the code in the first place. |
Well, @Butt4cak3 I actually moved my configs in that time so I P.S: glad to be in a community 👍 |
Sorry if I missed this, but what was the final decision on C++? 2-space indentation or 4? I agree with @Gathros here, 4-spaces seems more readable, but I don't mind using 2 if it's the standard. |
2-space indentation is the standard we've decided upon. |
@earthfail It seems like you used the right indentation scheme anyway, but one file contains mixed tabs and spaces. If you could clean that file up in the near future, that would be nice. Just get rid of the tabs and make sure it's properly indented. @leios C++ is the one point on the list that's not done yet. @ubsan opened that other PR about C++ formatting. I already changed the .editorconfig file to 2 spaces, but I'm waiting for a decision to be made over there. |
So, as far as the C++ conversation is concerned... I don't mind any formatting, so long as it's consistent. because @ubsan and @Gathros submit the most C / C++ code, I think the discussion should be primarily between the. Ubsan wanted to go with 2 spaces, Gathros didn't mind... So I guess we are going with 2 spaces unless someone else wants to weigh in. Also: ubsan seemed to indicate that it would be better to resolve this sooner than later in order to move on to other areas... |
Can we add Elm to the list? Something like:
|
@leios Well, then. This PR doesn't hold anyone back. This config file is only for an optional text editor plugin. @jiegillet Done! There's a link to the EditorConfig website in the top post. There is a plugin for Atom as well. It's convenient, but not required for contributions to the AAA. |
Alright. I added HTML and CSS and prepared the branch for a merge. (ping @leios) |
WOO MERGED! |
When merged, this pull request will add a configuration file for EditorConfig. EditorConfig is a collection of plugins that use the same configuration file. Plugins are available for many common text editors. Go to editorconfig.org for more information and plugin downloads.
The goal of adding such a configuration to the AAA is to make it easier for contributors to write consistently styled code throughout the entire project. The file will mainly contain two options for each language: "indent_style" and "indent_size" for spaces or "tab_width" for tabs.
This Pull Request exists as a place for discussion until we can agree on indentation styles for every language. Feel free to propose more languages that are not currently used in the AAA but could be in the future!
Here is a list of languages that will be included in the file.