Draft coding conventions

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Draft coding conventions

Post by carlopav »

I noticed FEM has a nice coding convention file.
What about if we copy it in the main Draft module folder and adapt it to our needs? @vocx
so we can slowly port the code to be consistent to it...
follow my experiments on BIM modelling for architecture design
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Draft coding conventions

Post by bernd »

would be cool if there would be not that much difference :)
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Draft coding conventions

Post by carlopav »

i meant to just change the module name :)
follow my experiments on BIM modelling for architecture design
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Draft coding conventions

Post by bernd »

carlopav wrote: Mon Jan 06, 2020 9:17 pm i meant to just change the module name :)
This will not work as FEM uses snake_case for python method and variable names ... interesting to know what else is different.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Draft coding conventions

Post by vocx »

carlopav wrote: Mon Jan 06, 2020 7:30 pm I noticed FEM has a nice coding convention file.
What about if we copy it in the main Draft module folder and adapt it to our needs? @vocx
so we can slowly port the code to be consistent to it...
Yes. Since Bernd uploaded his initial coding conventions, I copied the file to my computer and changed a few things to refer to Draft specifically; then I expected to make a pull request. But since Bernd continued adding to the coding conventions, I decided to wait until there were no more changes. This means Bernd does all the work and we just adapt it quickly.

It was not a priority because anyway not many people are contributing to Draft/Arch, and Yorik and I mostly comply with PEP8 conventions already.

When I started changing some stuff Bernd opened a thread to discuss this, where I mentioned some of the things that I was doing, Python codeformating Draft, Arch in the regard of pep8 etc.

I was mostly trying to fix the formatting of several Draft files, and provide documentation strings. In fact, my emphasis was on the documentation strings, and not the formatting itself, but that was done as well when no major changes were needed.

As per my different threads I am trying to improve the PEP8 style of Draft (see the links in Python) but this requires some work to avoid breaking previous code. For example, in the case of snake_case, I want to provide new snake_case_commands, and then aliases to the old names that use CamelCase; then the old code doesn't break. See Draft.py in pull request #2830 for how this should work.

The only thing I basically disagree with Bernd is the use of "black" to format Python. I hate that "black". It looks hideous.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Draft coding conventions

Post by bernd »

vocx wrote: Tue Jan 07, 2020 4:53 am The only thing I basically disagree with Bernd is the use of "black" to format Python. I hate that "black". It looks hideous.
ATM there is not code in FEM which uses FEM.

But yes the only difference we have are the line breaks. I have started to use line breaks the way black does it (only use one tab (4 spaces) for indent) and you prefere to use line breakes another way use as many tabs (x4 spaces) as the code before is long. I do not know how to describe these systems in short.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Draft coding conventions

Post by vocx »

bernd wrote: Tue Jan 07, 2020 5:32 am ...
But yes the only difference we have are the line breaks. I have started to use line breaks the way black does it (only use one tab (4 spaces) for indent) and you prefere to use line breakes another way use as many tabs (x4 spaces) as the code before is long. I do not know how to describe these systems in short.
Black

Code: Select all

mostly_affects_parentheses(with, some,
    hideous, results
):
It looks like a sad face at the end! SAD!

Best Python style

Code: Select all

best_alignment_of_parentheses(with, neat,
                              lines, aligned, to,
                              previous, line):
Black, also known as sad-style, produces code like this

Code: Select all

function_has_no_arguments(
):
SAD
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Draft coding conventions

Post by bernd »

vocx wrote: Tue Jan 07, 2020 5:53 am ...
Black

Code: Select all

mostly_affects_parentheses(with, some,
    hideous, results
):
...
FreeCAD FEM

Code: Select all

mostly_affects_parentheses(
    with, some, structured, results
):
or:

Code: Select all

mostly_affects_parentheses(
    with,
    some,
    structured,
    results
):
I do not mind removing the line which mentions black code formater from FEM code conventions as no FEM uses black ATM. But I like the parentheses way of indent, because the indent is on the left side and not far away on the right as seen in your example.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Draft coding conventions

Post by bernd »

vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Draft coding conventions

Post by vocx »

carlopav wrote: Mon Jan 06, 2020 7:30 pm ...
What about if we copy it in the main Draft module folder and adapt it to our needs? @vocx
...
Pull request #3191.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Post Reply