Coding. style

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
jnxd
Posts: 951
Joined: Mon Mar 30, 2015 2:30 pm
Contact:

Re: Coding. style

Post by jnxd »

wmayer wrote: Wed Apr 20, 2022 9:46 am
jnxd wrote: Wed Apr 20, 2022 9:11 am Mind hopping in with your inputs? Do you recall what the PR was where we talked about it?
https://github.com/FreeCAD/FreeCAD/pull ... r757918354
Thanks! Not even sure how you found it :oops:.
wmayer wrote: Wed Apr 20, 2022 9:46 am I don't see a problem with readability if auto instead of TopoDS_Shape was used because the call of TopoDS::Shell makes it obvious that s must be a TopoDS_Shape
I'm fine either way.
My latest (or last) project: B-spline Construction Project.
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Coding. style

Post by wmayer »

Thanks! Not even sure how you found it
It's a matter of using the correct filter. The PR is closed, you are the author and donovaly did the review. So, you get this filter

Code: Select all

is:closed is:pr author:AjinkyaDahale mentions:donovaly 
This results into 10 PRs and now you have to go through all of them and check the comments.
User avatar
adrianinsaval
Veteran
Posts: 5551
Joined: Thu Apr 05, 2018 5:15 pm

Re: Coding. style

Post by adrianinsaval »

wmayer wrote: Wed Apr 20, 2022 10:38 am

Code: Select all

is:closed is:pr author:AjinkyaDahale mentions:donovaly 
doesn't mentions:donovaly only work if someone writes @donovaly somewhere? I would think commenter:donovaly would be a more complete filter
User avatar
adrianinsaval
Veteran
Posts: 5551
Joined: Thu Apr 05, 2018 5:15 pm

Re: Coding. style

Post by adrianinsaval »

FreddyFreddy wrote: Wed Apr 20, 2022 7:40 am Thanks for the support! Will get there soon enough.
Nice, it's good to see new people with this attitude. I would recommend limiting the scope of your changes and submitting a PR to get feedback and know if you're on the right track. It's also easier to get your changes in if it's not a massive PR.
User avatar
jnxd
Posts: 951
Joined: Mon Mar 30, 2015 2:30 pm
Contact:

Re: Coding. style

Post by jnxd »

wmayer wrote: Wed Apr 20, 2022 10:38 am It's a matter of using the correct filter. The PR is closed, you are the author and donovaly did the review. So, you get this filter
adrianinsaval wrote: Wed Apr 20, 2022 3:11 pm doesn't mentions:donovaly only work if someone writes @donovaly somewhere? I would think commenter:donovaly would be a more complete filter
Thanks for the info, Werner and Adrian.
My latest (or last) project: B-spline Construction Project.
FreddyFreddy
Posts: 176
Joined: Wed Mar 09, 2022 3:15 am
Location: Oz

Re: Coding. style

Post by FreddyFreddy »

wmayer wrote: Wed Apr 20, 2022 7:56 am
FreddyFreddy wrote: Wed Apr 20, 2022 7:29 am The latter (leading _) I understand is all about not polluting the global space (plenty of that here). Not hard to fix, but might need some concensus on naming convention. Any inputs?
Concrete example?
From https://en.cppreference.com/w/cpp/language/identifiers
A valid identifier must begin with a non-digit character ... exceptions:
    the identifiers with a double underscore anywhere are reserved;
      the identifiers that begin with an underscore followed by an uppercase letter are reserved;
        the identifiers that begin with an underscore are reserved in the global namespace.

        "Reserved" here means that the standard library headers #define or declare such identifiers for their internal needs, the compiler may predefine non-standard identifiers of that kind, and that name mangling algorithm may assume that some of these identifiers are not in use. If the programmer uses such identifiers, the behavior is undefined.
        Example in exception.cpp

        Code: Select all

         'static PyMethodDef* __AppMethods = nullptr;
        FreddyFreddy
        Posts: 176
        Joined: Wed Mar 09, 2022 3:15 am
        Location: Oz

        Re: Coding. style

        Post by FreddyFreddy »

        Going back to the original question ...

        I have hit a snag. Part of my normal workflow is to occasionally hit the IDE's 'format' to enforce uniform layout and clean up any messes I made. That way there's one thing less to think about when typing.

        BUT formatting Application.cpp produced hundreds of changes due to differences between my settings and the freecad code.

        I tried to change my settings to match fc, but even within the one fc file there are different styles. Spaces, brackets etc etc etc

        Personally I like things to be uniform. But submitting hundreds of changes just to please me is obviously not an option!

        Help?!?
        wmayer
        Founder
        Posts: 20307
        Joined: Thu Feb 19, 2009 10:32 am
        Contact:

        Re: Coding. style

        Post by wmayer »

        Thx.
        FreddyFreddy wrote: Wed Apr 20, 2022 10:10 pm Example in exception.cpp
        It's in Application.cpp.

        the identifiers with a double underscore anywhere are reserved;
        the identifiers that begin with an underscore are reserved in the global namespace.
        The easiest is to move the variable into anonymous namespace which is in anyway the preferred way in modern C++.

        Code: Select all

        namespace {
        static PyMethodDef* AppMethods = nullptr;
        }
        
        FreddyFreddy
        Posts: 176
        Joined: Wed Mar 09, 2022 3:15 am
        Location: Oz

        Re: Coding. style

        Post by FreddyFreddy »

        wmayer wrote: Thu Apr 21, 2022 7:44 am
        FreddyFreddy wrote: Wed Apr 20, 2022 10:10 pmExample in exception.cpp
        It's in Application.cpp.
        Yeah! That one! (Tks)
        wmayer wrote: Thu Apr 21, 2022 7:44 am The easiest is to move the variable into anonymous namespace which is in anyway the preferred way in modern C++.
        That sounds easy enough! One for down the track a bit?!
        FreddyFreddy
        Posts: 176
        Joined: Wed Mar 09, 2022 3:15 am
        Location: Oz

        Re: Coding. style

        Post by FreddyFreddy »

        Re the format question, maybe cmake-format is a good option.
        cmake-format can format your listfiles nicely so that they don’t look like crap.
        Seems to work with a bunch of editors/ide's. I think a file is placed in the project root. CLion for example will use it if it is there. It can be initialised from quite a long list of defaults. qt was mentioned here previously. I don't see that listed in cmake doc, but it is one option in CLion.

        Is this a known good (or bad) idea?

        EDIT: Am confusing myself. The one in CLion is clang-format (part of LLVM project) and seems the most popular.
        Post Reply