Python codeformating Draft, Arch in the regard of pep8 etc

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Python codeformating Draft, Arch in the regard of pep8 etc

Post by yorik »

About import functions not being at the top: The reason is indeed the speed. Most of the Draft and Arch files are loaded at startup, so their commands are immediately available. However, importing all the bulk of heavyweight modules (Part, pivy, qt...) at start would delay startup a lot. Try for example to load the BIM workbench at startup, where it happens (didn't do my homework there yet :oops: ), you'll see the difference...

this is a golden rule since FreeCAD inception, do not load Part at module init...
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Python codeformating Draft, Arch in the regard of pep8 etc

Post by carlopav »

Any advice on codeformatting Yorik?
I did find very useful this article by @Moult https://sevenstrokes.net/learn-how-write-good-code .
Maybe it is off topic... But it was really helpful to me.
follow my experiments on BIM modelling for architecture design
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Python codeformating Draft, Arch in the regard of pep8 etc

Post by yorik »

TBH I'm not the right person to ask about code formatting as I write pretty shitty code :D

My programming guru, a guy called W. Mayer, not sure if you have heard of him, once said: "It doesn't matter how your code is formatted, as long as it is well commented"

I guess that mostly comes down to try to be nice and clear to others when writing code and spare them as much effort as possible..
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Python codeformating Draft, Arch in the regard of pep8 etc

Post by bernd »

yorik wrote: Mon Aug 12, 2019 5:35 pm TBH I'm not the right person to ask about code formatting as I write pretty shitty code :D

My programming guru, a guy called W. Mayer, not sure if you have heard of him, once said: "It doesn't matter how your code is formatted, as long as it is well commented"
and you need to live in another star to be able to understand all the different formated code. You both guys do live on this other star :D (which one of the main reasons FreeCAD is what it is) Since I am just a poor programmer I find it very very helpful for understanding the code to have it formated a special way. May be this is even a preference of a poor programmer, he just needs his formated code. Nevermind I am very happy with well formated FEM python code but step by step get used to the Arch and Draft way too.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Python codeformating Draft, Arch in the regard of pep8 etc

Post by bernd »

carlopav wrote: Sat Aug 10, 2019 9:05 pm I did find very useful this article by @Moult https://sevenstrokes.net/learn-how-write-good-code .
thanks for the link. Gave me some nice new input too.
chrisb
Veteran
Posts: 54288
Joined: Tue Mar 17, 2015 9:14 am

Re: Python codeformating Draft, Arch in the regard of pep8 etc

Post by chrisb »

carlopav wrote: Sat Aug 10, 2019 9:05 pm I did find very useful this article by @Moult https://sevenstrokes.net/learn-how-write-good-code .
thanks for the link. Gave me some nice new input too.
Interesting reading, but I'm absolutely not agreeing with his recommendation concerning comments. I agree that code should be written as if there were no comments, i.e. not relying on the comment to understand the code. But there should always be comments explaining the idea behind the code. I guess that's what he means saying to comment "why" and not "how".
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Python codeformating Draft, Arch in the regard of pep8 etc

Post by vocx »

Now that I've added a bunch of docstrings to various files in Draft, there is more complete programming documentation.

For example, the following image is automatically generated by Doxygen, from Draft/WorkingPlane.py. It's not particularly pretty, because Doxygen just shows the text verbatim. But I hope to investigate in the future the use of Sphinx to produce better documentation.
alignToFace_doxygen.png
alignToFace_doxygen.png (55.82 KiB) Viewed 1782 times
To compile the documentation, use make DevDoc in the top level of the FreeCAD source tree. See Source documentation for more information.
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
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Python codeformating Draft, Arch in the regard of pep8 etc

Post by yorik »

Excellent job!! Having a better API documentation is a very important point and we are seriously lacking behind! Very happy you're tackling this
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Python codeformating Draft, Arch in the regard of pep8 etc

Post by Kunda1 »

This is awesome! Thanks @vocx for leaning in hard on this issue. This is a game changer
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Python codeformating Draft, Arch in the regard of pep8 etc

Post by carlopav »

+1
follow my experiments on BIM modelling for architecture design
Post Reply