pfalstad / circuitjs1

Electronic Circuit Simulator in the Browser
GNU General Public License v2.0
1.71k stars 286 forks source link

Code Style: Indentation settings? #35

Open fritzw opened 1 year ago

fritzw commented 1 year ago

I'm trying to implement a few features that I hope you would find useful. However, the current indentation style with tabs vs. spaces appears rather random (see attached screenshot from CirSim.java). It looks okay when setting the Tab width to 8 and indenting by 4 spaces, but sadly that is not possible in VSCode right now (https://github.com/microsoft/vscode/issues/5394), in contrast to e.g. vim. :-(

@pfalstad: Do you prefer any specific indentation style for new contributions? I understand that unifying all the old code would mess up the git history, so that is out of scope. In the absence of any guidelines I would use spaces-only for new code because editors can't mess that up and using tabs consistently leads to messes.

image

pfalstad commented 1 year ago

I prefer tabs set to 8, with 4 space indent. (spaces only is OK.) That is what all the java code originally used. I think that got messed up somewhere. Perhaps Iain was using different settings, or maybe I was using the wrong settings in eclipse for a while.

fritzw commented 1 year ago

Adding a .editorconfig file to the repository could help people get the settings right. VS Code just recently got the ability to separately set the indent width and the tab width. Unfortunately the EditorConfig plugin seems unable to set these settings correctly for now (https://github.com/editorconfig/editorconfig-vscode/issues/346), but at least I can set them manually to correctly render the Java files.

Also, VS Code will not automatically merge 8 spaces into a tab. This could be done with an automatic replace-on-save action, but that would affect the entire file, not just changed parts. Guess we will have to live with inconsistent spacing.

But since you said that spaces only are fine for you, we can probably close this issue. Or leave it open until a working .editorconfig has been commited.

H-Dynamite commented 7 months ago

Format code using IDEA [3422802b56833c66e7f1908a1483112b1fff6fc1](https://github.com/SEVA77/circuitjs1/commit/3422802b56833c66e7f1908a1483112b1fff6fc1)