Hard Light Productions Forums

Off-Topic Discussion => Programming => Topic started by: pecenipicek on April 01, 2014, 04:06:45 pm

Title: My pet python project
Post by: pecenipicek on April 01, 2014, 04:06:45 pm
I've released my project for fan control on linux on  github (https://github.com/vrga/pyFanController)


I'd appreciate it if someone well versed in python and or OOP could guide me to a better codebase :)
Title: Re: My pet python project
Post by: Spicious on April 02, 2014, 04:42:42 am
First off, go read http://legacy.python.org/dev/peps/pep-0008/ and http://google-styleguide.googlecode.com/svn/trunk/pyguide.html and follow them.
Use the provided logging library instead of rolling your own; it's good: https://docs.python.org/3/howto/logging.html.
Don't discard exceptions; an object failing to construct really should inform the caller.
Use tuples instead of lists for fixed sized things.
Use list and dict literals ([] and {}) instead of list() and dict().
Don't use __del__ if at all possible.
Title: Re: My pet python project
Post by: Kopachris on April 02, 2014, 06:30:01 am
I was going to mention some of the stuff Spicious mentioned, but then I realized I'm not exactly the right person to ask for Python writing style advice.  My code is always a mess.  It works, but it's a mess.
Title: Re: My pet python project
Post by: pecenipicek on April 02, 2014, 12:31:35 pm
First off, go read http://legacy.python.org/dev/peps/pep-0008/ and http://google-styleguide.googlecode.com/svn/trunk/pyguide.html and follow them.
i find pep8 to be full of crap in some regards honestly. i've sticked with it mostly even though i find the 4 spaces way too cramped.

Quote
Use the provided logging library instead of rolling your own; it's good: https://docs.python.org/3/howto/logging.html.
I've missed that one whilst looking for builtins  :sigh:

Quote
Don't discard exceptions; an object failing to construct really should inform the caller.
And what? Have specific handlers in the caller? They are mostly being discarded at the time being anyhow as i hit a bit of a wall on how to proceed in that regard anyhow.
And i'm perfectly fine with them killing the program if they barf on a configuration error. I just need to set up the logging properly.

Quote
Use tuples instead of lists for fixed sized things.
Is there  a particular reason for this? And do contents of tuples have to be fixed as well?
Quote
Use list and dict literals ([] and {}) instead of list() and dict().
i blame my php background for those... i'll rework it :)
Quote
Don't use __del__ if at all possible.
it was the only reliable way to purge the pid on program exit that i could figure out, as running two instances tended to mess some things up fiercely... Do you reccomend a better way?


btw, Kopachris, i'm still open to ideas and reccomendations :)