Replies: 14 comments 15 replies
-
|
@Lomholy let me first indicate that I more or less agree: Historically I have myself “lived with” whatever indentation the original author chose and tried to stick with that in the individual file - or if I changed the whitespace / indentation done that work in a separate commit. History aside…
I have a prototype in place at https://github.com/willend/McCode/tree/clangformat-experimental, I simply asked an AI to:
I would prefer to stick with a “contributor/developer tool” and not automate via CI for now… (The Windows CI-tests are completely overwhelmed by the sheer number of changed comps/instrs: |
Beta Was this translation helpful? Give feedback.
-
|
(… And if anyone was in doubt: I hate IDE’s/editors that auto-indents the code…) |
Beta Was this translation helpful? Give feedback.
-
|
@willend weren't you on vacation? ;) Jokes aside, this is exactly the sort of thing I was hoping for. I agree with 4 space indentation, but I honestly dont think we should indent each section per default. I really appreciate the 120 column limit. I agree that 80 is too small, but an upper limit is nice to have, just to be able to keep code somewhat together. I think I will warn against using our own "homemade" auto indenter, as there are so many edge cases... so sticking to clang-format or another tool is probably better. Having the homemade solution as a fallback is of course fine for a start, but in the long run, it might end up hiding issues. One thing I would add is to indent in preprocessor directives i.e #ifdef and others like it. It seems that clang-format has this under IndentPPDirectives. (... And if anyone is in doubt: I don't mind auto indenting IDE's. That means I don't have to do it...) |
Beta Was this translation helpful? Give feedback.
-
|
@Lomholy vacation also sometimes means peace and quite for ‘fun and hobbies’, for me a gray-zone that at times overlaps with actual work… ;-) The branch mentioned above was by no means meant as ‘the solution’. Simply a demonstrator to outline how I would personally prefer this implemented. And this time round I experimented by ‘letting the AI do the coding’… (“Det er det de unge vil ha’…” ;-) ) I think it would be sensible to converge on:
That said, my practical experience with using clang-format is at this point limited, but you have (had your IDE) run it I guess?
// 1.
my_own_very_long_typename_pointer* Variable_name_that_spells_out_too_much_Maybe_Even_caMeL_case;
// 2.
/* Commented section containing ‘dead code’, i.e. some random, earlier version of now production code existing elsewhere
in the file */
/* my_own_very_long_typename_pointer_OLD* Variable_name_that_spells_out_too_much_Maybe_Even_caMeL_case_OLD; */
To me whitespace is not just whitespace - and sending commits that change other users code drastically at the structural level MUST happen independently of actual code/algorithmic changes. Otherwise later effort to disentangle / deconstruct a code issue becomes so much more time- and energy-consuming... |
Beta Was this translation helpful? Give feedback.
-
|
@willend The tool actually worked pretty well, which I suppose is why I gave my input. Tinkering a little with it made it use a .clang-format file which I have defined. I ran it for all the instruments and components (I think). Regarding the indenting, I am not much of a fan of two space (I do actually tend toward the old guide of "if your indentation is making your code wide, then you are indenting too much.") I also tend to agree with you on the 80 char limit, but with the codebase in its current state, I think it would make the code more unreadable (in part due to the long variable and struct names used), than if we stick to a 120 char limit. Regarding the coding styles, I completely agree with your two suggestions, but noting that they are guidelines, not absolutes, as all code guidelines are. One thing I would like, but I think is very much against everybody elses opinion is this: Functions should generally fit unto a single printed page in your normal font. This usually makes your function keep a red thread, and forces you to split up the code into smaller, more understandable bits. I would argue that TRACE should also be such a function, albeit I know many disagree (or at least the written code disagrees.).
Both those auto indenter issues are solved if you, inside a project, agree on which formatter to use. |
Beta Was this translation helpful? Give feedback.
-
|
@Lomholy thanks for playing with the tool and adapting, let’s see what we will eventually arrive at.
Hmm maybe, I will see if I can figure that out. :-) The issue is that the
You are mentioning two space - not four space, was that a mistake? It seems so if you are at the same time making the argument that "if your indentation is making your code wide, then you are indenting too much.”? :-) I will have to insist that we need indentation inside the
Whatever we end up agreeing I think ought to become available both within the devel tree as e.g. a .py script and as (for instance) a VS code extension. This gives room for both “old dogs that have a hard time learning new tricks” and the “youthful youth and their AI-driven IDE approaches”. ;-) |
Beta Was this translation helpful? Give feedback.
-
|
Heh, one more observation:
I simply can not wrap my head around these big commits that contain edits to 1000 files… :-) |
Beta Was this translation helpful? Give feedback.
-
My intent is that I enjoy four space, since four space makes you see the indentation more clearly. The argument against four space is of course real estate, where I mean that if you are lacking space because you have indented, you have indented too much. But maybe we should go with two spaces if we insist on indenting inside sections as default.
This will be solved if we do the formats one category at a time, if I understand the issue correctly?
I wholeheartedly agree. |
Beta Was this translation helpful? Give feedback.
-
Only partly, what will be solved is the “overwhelming” ( or at least some of it). |
Beta Was this translation helpful? Give feedback.
-
|
@Lomholy script-code only branch is now at https://github.com/mccode-dev/McCode/tree/formatter-tool-only with minor tweaks. Do you have required syntax to allow the initial 2-char indentation within %{%} blocks? |
Beta Was this translation helpful? Give feedback.
-
|
Cool, will check out the issues relating to %include and the Union_mesh to see if I can figure out a way around / what is happening. (I suppose it is a matter of regex “massage”.) |
Beta Was this translation helpful? Give feedback.
-
|
@Lomholy I am quite happy with how our little prototype performs now - and have a “solution” in place to avoid clang messing with the %include lines… |
Beta Was this translation helpful? Give feedback.
-
|
I think I’ve found a good solution (admittedly not in the
Also, I found that We could then start a slower process to identify where very such long in-line comments occur, fix them and then later apply an 80 char column restriction and a ‘soft’ code of conduct formulation to prefer non-inlined comments. Test output looks OK for all of the comp categories that I applied: (And I am thinking I will not touch / then flush |
Beta Was this translation helpful? Give feedback.
-
|
Tool prototype is now in place on main and PRs have been added for McStas non- McXtrace work currently pending. |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
Sometimes when we make large components and work on them multiple people, the indentation gets mixed up. We use different coding styles and paradigms, which by themselves are fine, but when mixed they get confusing to read. This discussion is an extension of #2308 which showcased the default clang formatter.
I therefore propose that we choose a formatter that we accept to be used when working on mcstas components.
I propose that we either use the clang-format formatter or the astyle (Artistic style) formatter.
I will spend some time in the coming days, coming up with which settings could be used for a formatter, and showcase what this results in for a couple of different examples, namely the Monochromator_Bent components and the Union_mesh component.
Looking forward to hearing your thoughts on this!
Beta Was this translation helpful? Give feedback.
All reactions