Re: [GRASS-dev] Replace GNU Indent with ClangFormat?

2022-03-21 Thread Vaclav Petras
On Mon, 21 Mar 2022 at 10:01, Nicklas Larsson via grass-dev <
grass-dev@lists.osgeo.org> wrote:

> ...There were attempts to do this [2, 3], but numerous problem
> arose...which are based on GNU Indent [4]. These problem are probably
> originate in the comparatively limited functionality and lack of active
> development on GNU Indent.
>

Additionally, the C++ support in GNU Indent is limited:

While an attempt was made to get indent working for C++, it will not do a
good job on any C++ source except the very simplest.
https://www.gnu.org/software/indent/manual/indent/Bugs.html

I think the note in the docs was there even before C++11.


> I have created a `.clang-format` file with the settings as close as
> possible to the ones in `grass_indent.sh` (somewhat outdated described in
> [7]).
>

I don't think the style is set in stone. This is perhaps for a next phase,
but unless a strong standard emerges for C/C++, we may consider switching
to something which is close to Black given our mixed code base. Function
signatures and calls would be the big change there. However, the closing
parenthesis on a separate line typical to Black is available only in the
upcoming ClangFormat 14.

On the other hand, yielding to some 3rd party standard seems like a good
idea especially for all the C++ syntax.


> Now the question is first of all: is using ClangFormat something the GRASS
> dev community (you) would want or could live with for this project?
>

+1. Being tool-independent is not possible here and ClangFormat seems to do
the job.


> And if so, what version of ClangFormat should then be the starting point
> (what do you have reasonably easy available for your dev platform)? The
> present settings in the PR are derived from ClangFormat 13, but could
> possibly be back ported if really needed.
>

You can run a specific version locally using Docker thanks to a related
GitHub Action:

https://github.com/DoozyX/clang-format-lint-action#run-locally

Harder to integrate in your editor, but at least something. (Yes, your
favorite editor may already have support for ClangFormat.)
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] Replace GNU Indent with ClangFormat?

2022-03-21 Thread Anna Petrášová
+1

On Ubuntu 20.04 LTS, there is ClangFormat 12, I suppose there will be 13 in
the upcoming 22.04 release.

Anna

On Mon, Mar 21, 2022 at 10:01 AM Nicklas Larsson via grass-dev <
grass-dev@lists.osgeo.org> wrote:

> Formatting the C and C++ code, making a consistent coding style was
> proposed for G8 [1]. Unfortunately, it didn't make it. There were attempts
> to do this [2, 3], but numerous problem arose using `util/grass_indent.sh`
> and its batch script `util/grass_indent_ALL.sh`, which are based on GNU
> Indent [4]. These problem are probably originate in the comparatively
> limited functionality and lack of active development on GNU Indent.
>
> I just filed a PR [5] with the aim to replace GNU Indent with ClangFormat
> [6] and later (separately!) make a bulk formatting of all the code. Running
> clang-format on all *.h|*.c|*.cpp (some 3000+) files goes fine without any
> issues. I have created a `.clang-format` file with the settings as close as
> possible to the ones in `grass_indent.sh` (somewhat outdated described in
> [7]).
>
> ClangFormat is a working program in active development, therefore its
> performance is version dependent (similar to what we have had with Black
> for Python). On the other hand, its adaptation is increasing, now used in
> several big and small projects.
>
>
> Now the question is first of all: is using ClangFormat something the GRASS
> dev community (you) would want or could live with for this project?
> And if so, what version of ClangFormat should then be the starting point
> (what do you have reasonably easy available for your dev platform)? The
> present settings in the PR are derived from ClangFormat 13, but could
> possibly be back ported if really needed.
>
> Please check out the settings, as well as some code files formatted for
> illustrational purposes only, at the PR [5].
>
>
> Best,
> Nicklas
>
>
>
> [1]
> https://trac.osgeo.org/grass/wiki/Grass8Planning#Codeorganisationcodingstyles
> [2] https://github.com/OSGeo/grass/issues/1630
> [3] https://github.com/OSGeo/grass/pull/2270
> [4] https://www.gnu.org/software/indent/
> [5] https://github.com/OSGeo/grass/pull/2272
> [6] https://clang.llvm.org/docs/ClangFormat.html
> [7] https://trac.osgeo.org/grass/wiki/Submitting/C#Indentation
>
> ___
> grass-dev mailing list
> grass-dev@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-dev
>
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


[GRASS-dev] Replace GNU Indent with ClangFormat?

2022-03-21 Thread Nicklas Larsson via grass-dev
Formatting the C and C++ code, making a consistent coding style was proposed 
for G8 [1]. Unfortunately, it didn't make it. There were attempts to do this 
[2, 3], but numerous problem arose using `util/grass_indent.sh` and its batch 
script `util/grass_indent_ALL.sh`, which are based on GNU Indent [4]. These 
problem are probably originate in the comparatively limited functionality and 
lack of active development on GNU Indent.

I just filed a PR [5] with the aim to replace GNU Indent with ClangFormat [6] 
and later (separately!) make a bulk formatting of all the code. Running 
clang-format on all *.h|*.c|*.cpp (some 3000+) files goes fine without any 
issues. I have created a `.clang-format` file with the settings as close as 
possible to the ones in `grass_indent.sh` (somewhat outdated described in [7]).

ClangFormat is a working program in active development, therefore its 
performance is version dependent (similar to what we have had with Black for 
Python). On the other hand, its adaptation is increasing, now used in several 
big and small projects.


Now the question is first of all: is using ClangFormat something the GRASS dev 
community (you) would want or could live with for this project?
And if so, what version of ClangFormat should then be the starting point (what 
do you have reasonably easy available for your dev platform)? The present 
settings in the PR are derived from ClangFormat 13, but could possibly be back 
ported if really needed.

Please check out the settings, as well as some code files formatted for 
illustrational purposes only, at the PR [5].


Best,
Nicklas



[1] 
https://trac.osgeo.org/grass/wiki/Grass8Planning#Codeorganisationcodingstyles
[2] https://github.com/OSGeo/grass/issues/1630
[3] https://github.com/OSGeo/grass/pull/2270
[4] https://www.gnu.org/software/indent/
[5] https://github.com/OSGeo/grass/pull/2272
[6] https://clang.llvm.org/docs/ClangFormat.html
[7] https://trac.osgeo.org/grass/wiki/Submitting/C#Indentation

___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev