You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With an active and diverse developer community we need to spell out more clearly what we want the code to look like, i.e. we need a Style Guide.
Related questions have come up recently in #392 and #393 but there are also the recurring discussions about length of lines etc., in particular see #216 !
A very basic guideline consists of the editor settings:
I think last time we looked at line length, 80 was far too small, so 100/120 is probably better. I'm also happy to be very flexible about this (for readability).
We looked at automated systems (autopep8, yapf) for style and they kind of work, but still require a manual pass afterwards.
One option is we could add a pep8 check of some sort to travis, This would be a little annoying, but would make sure that the code doesn't gradually deteriorate after the #216 tidy up.
@richardjgowers 100/120 is too long. But just write as long as we can, and like you said, to use autopep8 or yapf to format. Problem solved.
I don't think adding pep8 check is a good idea. Which program you're going to use? I used programs to check pandas' code and there are some failed sections.
I think using a pep8 checker is a good idea. I started using one for MDSynthesis a while back, and though I felt it was a bit too strict at first (and painful to fix all the violations), I now consider it invaluable for maintaining consistent and readable style throughout the library. I think I would enjoy diving into MDAnalysis code more if something like this was used to enforce pep8 conventions. Silly inconsistencies in style are distracting, and make it hard for others to contribute.
Also, 80 characters is just fine. I don't think there's really a compelling argument for going over that, since it just makes it harder to review code, either locally or on Github. I do not consider 100 or 120 characters acceptable for readability.
I found that using 80 columns is the best compromise when I work on my laptop and want to have
two documents side by side (14" with FullHD resolution). I think the maximal line length I can then watch without linewrapping is something between 90 and 100. This is also true for people using tiling window managers (or editors emulating them like emacs/vim). In my personal projects I use 80 characters and above that limit when it helps readability. (As a side effect I use short descriptive names and avoid deep nesting of loops by moving things into reusable functions)
Code linters
YAPF seems to me to be better then autopep8 at a first glance, I think I have some time this week to play with the settings some more. But I guess it won't produce perfect results since code-linting in python is just really hard. I haven't defaulted to using code linters yet for my python projects but in my C++ projects I have emacs configured to run clang-format on every save (This is a huge help since I completely stopped to think about getting the formating right myself). Since not everybody is using emacs a simple solution might be an installable git-hook that applies the code-linter to every added file.
I would also be against a pep8 checker on travis. I see pep8 as a guideline I should mostly follow
but sometimes it just isn't a good fit for the code.
Most modern IDE's for python have warning about PEP8 violations enabled by default (see pycharm) and for other editors there are good plugins. For emacs I use Elpy, Python-mode is similar for vim.
Imports
I'm for using common abbreviations for packages in the python-scientific stack. Most people are
used to them and writing them out is more confusing (at least for me).
I am actually very low tech and old fashioned too, using only vim with very minimal support.
But I bet we can update the default in .vimrc (or .emacs??) too.
I like having test data and tests together, instead of relying on an internet connection to pull in data that might or might not be out of date
Inside of the git repository the test and test-data would still be there. So as a developer running the test-suite I wouldn't have to download any files from the Internet. The thing that changes is that we don't over the tests as a package for users anymore. We over that users can download individual files as for the example scripts that we have in the documentation.
PDB, XTC=mda.load_datasets(['PDB', 'XTC'])
u=mda.Universe(PDB, XTC)
# show how a particular function is supposed to be used
So an internet connection would be required to run the examples from a user-perspective. What we do loose with such an approach is that I could verify a package download from PyPi by running the test-suite in the MDAnalysisTests package. None of the other packages I use/know bothers with that, it's just a decision we have to make if we want users to be able to verify somehow that the package they installed works as intended.
Git commit Messages
Actually I think the blog-post from Tim-Pope I linked earlier is a pretty good guideline of what a good commit message is. As I'm teaching colleagues git now I noticed that I can preach to them as much as I want how they should write commit messages it works best if I show them what I mean for a commit of their own. It takes time because I have to do it for each one individually but it is the only thing I found that works. Maybe we could write that a Lab-Book is a good analogy to the git-log.
I updated the Style Guide on the wiki. I think it now contains everything discussed here but perhaps someone else (such as the usual suspects @richardjgowers , @kain88-de , @tylerjereddy ) can do a quick read-through and if need be, add missing parts.
Once this issue is closed, we'll declare the Style Guide to be official. I'll send an email to the dev list that the Style Guide is now the law of the land, and from then on code reviews can fully reference it to ask for amendments in line with the Style Guide.
Re: @kain88-de 's comment on adding tests back into the package: For right now the Style Guide says that we have the split between package and testsuite; this discussion is really a separate issue (so by all means, open one) and has not been decided so for right now, the status-quo prevails.
Maybe add that we should use the six module for ranges and zip in new code like we do in the tests. So new code would already be Python 3 compatible. We have to add it later anyway so we might just do it now
Maybe add that we should use the six module for ranges and zip in new code like we do in the tests. So new code would already be Python 3 compatible. We have to add it later anyway so we might just do it now
Good idea, can you add an entry + example, please?
Otherwise there is the thing about 79 or 80 characters limit left.
I vaguely recalled that there was a discussion but didn't find a conclusion. You were one of the proponents of 80 chars; I really have no strong feelings either way and it would be fine with me to diverge from PEP8 in that respect.
Activity
richardjgowers commentedon Aug 29, 2015
I think last time we looked at line length, 80 was far too small, so 100/120 is probably better. I'm also happy to be very flexible about this (for readability).
We looked at automated systems (autopep8, yapf) for style and they kind of work, but still require a manual pass afterwards.
One option is we could add a pep8 check of some sort to travis, This would be a little annoying, but would make sure that the code doesn't gradually deteriorate after the #216 tidy up.
hainm commentedon Aug 29, 2015
@richardjgowers 100/120 is too long. But just write as long as we can, and like you said, to use autopep8 or yapf to format. Problem solved.
I don't think adding pep8 check is a good idea. Which program you're going to use? I used programs to check pandas' code and there are some failed sections.
dotsdl commentedon Aug 29, 2015
I think using a pep8 checker is a good idea. I started using one for MDSynthesis a while back, and though I felt it was a bit too strict at first (and painful to fix all the violations), I now consider it invaluable for maintaining consistent and readable style throughout the library. I think I would enjoy diving into MDAnalysis code more if something like this was used to enforce pep8 conventions. Silly inconsistencies in style are distracting, and make it hard for others to contribute.
Also, 80 characters is just fine. I don't think there's really a compelling argument for going over that, since it just makes it harder to review code, either locally or on Github. I do not consider 100 or 120 characters acceptable for readability.
kain88-de commentedon Sep 1, 2015
80 column limit
I found that using 80 columns is the best compromise when I work on my laptop and want to have
two documents side by side (14" with FullHD resolution). I think the maximal line length I can then watch without linewrapping is something between 90 and 100. This is also true for people using tiling window managers (or editors emulating them like emacs/vim). In my personal projects I use 80 characters and above that limit when it helps readability. (As a side effect I use short descriptive names and avoid deep nesting of loops by moving things into reusable functions)
Code linters
YAPF seems to me to be better then autopep8 at a first glance, I think I have some time this week to play with the settings some more. But I guess it won't produce perfect results since code-linting in python is just really hard. I haven't defaulted to using code linters yet for my python projects but in my C++ projects I have emacs configured to run clang-format on every save (This is a huge help since I completely stopped to think about getting the formating right myself). Since not everybody is using emacs a simple solution might be an installable git-hook that applies the code-linter to every added file.
I would also be against a pep8 checker on travis. I see pep8 as a guideline I should mostly follow
but sometimes it just isn't a good fit for the code.
btw great talk about the topic
https://www.youtube.com/watch?v=wf-BqAjZb8M
Syntax Checkers
Most modern IDE's for python have warning about PEP8 violations enabled by default (see pycharm) and for other editors there are good plugins. For emacs I use Elpy, Python-mode is similar for vim.
Imports
I'm for using common abbreviations for packages in the python-scientific stack. Most people are
used to them and writing them out is more confusing (at least for me).
hainm commentedon Sep 1, 2015
I have habit writing free style and then use
yapfto reformat.yapf -i my_file.py. :Dhainm commentedon Sep 1, 2015
and I found putting those lines in the top of the code makes me very distracting.
orbeckst commentedon Sep 1, 2015
On 1 Sep, 2015, at 13:15, Hai Nguyen wrote:
Is it because you're not using a decent editor? ;-)
(These lines are to stay because I am old fashioned and don't want to rely on automated formatting but have my emacs know what the settings are.)
hainm commentedon Sep 1, 2015
@orbeckst
I am actually very low tech and old fashioned too, using only vim with very minimal support.
But I bet we can update the default in .vimrc (or .emacs??) too.
this is all in my
.vimrc:Dorbeckst commentedon Sep 1, 2015
On 1 Sep, 2015, at 13:22, Hai Nguyen wrote:
I like it publicly stated and semi-enforced whenever one loads the file.
kain88-de commentedon Sep 5, 2015
I have another item for the list. commit messages
Having good commit messages makes git blame much nicer to use and finding out the reason for changes is much faster.
orbeckst commentedon Sep 5, 2015
I added it to the list.
On 5 Sep, 2015, at 12:00, kain88-de wrote:
Oliver Beckstein * orbeckst@gmx.net
skype: orbeckst * orbeckst@gmail.com
25 remaining items
kain88-de commentedon Sep 23, 2015
Test Data and separate package
Inside of the git repository the test and test-data would still be there. So as a developer running the test-suite I wouldn't have to download any files from the Internet. The thing that changes is that we don't over the tests as a package for users anymore. We over that users can download individual files as for the example scripts that we have in the documentation.
So an internet connection would be required to run the examples from a user-perspective. What we do loose with such an approach is that I could verify a package download from PyPi by running the test-suite in the MDAnalysisTests package. None of the other packages I use/know bothers with that, it's just a decision we have to make if we want users to be able to verify somehow that the package they installed works as intended.
Git commit Messages
Actually I think the blog-post from Tim-Pope I linked earlier is a pretty good guideline of what a good commit message is. As I'm teaching colleagues git now I noticed that I can preach to them as much as I want how they should write commit messages it works best if I show them what I mean for a commit of their own. It takes time because I have to do it for each one individually but it is the only thing I found that works. Maybe we could write that a Lab-Book is a good analogy to the git-log.
orbeckst commentedon Oct 22, 2015
I updated the Style Guide on the wiki. I think it now contains everything discussed here but perhaps someone else (such as the usual suspects @richardjgowers , @kain88-de , @tylerjereddy ) can do a quick read-through and if need be, add missing parts.
Once this issue is closed, we'll declare the Style Guide to be official. I'll send an email to the dev list that the Style Guide is now the law of the land, and from then on code reviews can fully reference it to ask for amendments in line with the Style Guide.
orbeckst commentedon Oct 22, 2015
Re: @kain88-de 's comment on adding tests back into the package: For right now the Style Guide says that we have the split between package and testsuite; this discussion is really a separate issue (so by all means, open one) and has not been decided so for right now, the status-quo prevails.
kain88-de commentedon Oct 22, 2015
Maybe add that we should use the six module for ranges and zip in new code like we do in the tests. So new code would already be Python 3 compatible. We have to add it later anyway so we might just do it now
orbeckst commentedon Oct 22, 2015
On 22 Oct, 2015, at 13:59, kain88-de wrote:
Good idea, can you add an entry + example, please?
Oliver Beckstein * orbeckst@gmx.net
skype: orbeckst * orbeckst@gmail.com
kain88-de commentedon Oct 22, 2015
I'll add the part about python 2 and 3 compatibility.
Otherwise there is the thing about 79 or 80 characters limit left.
Besides of that things look good to me.
orbeckst commentedon Oct 22, 2015
On 22 Oct, 2015, at 14:20, kain88-de wrote:
I vaguely recalled that there was a discussion but didn't find a conclusion. You were one of the proponents of 80 chars; I really have no strong feelings either way and it would be fine with me to diverge from PEP8 in that respect.
kain88-de commentedon Oct 22, 2015
I'm also ok with either one. I just have to edit the emacs mode-line to a fill-column of 79 so that emacs does the right thing in MDAnalysis.
kain88-de commentedon Oct 22, 2015
Oh and the thing with the test. I think we can reevaluate that once we have restructured the tests, until then it's fine right now.
orbeckst commentedon Oct 24, 2015
Let's settle on the canonical 79 chars (if nothing else, removes one paragraph from the style guide because we can say "like PEP8").
orbeckst commentedon Oct 24, 2015
Style Guide is up and running and from henceforth the law of the land.
(Need to add the SG as a file CONTRIBUTING.rst or HACKING.rst to the repo... but will raise a separate issue.)
kain88-de commentedon Oct 24, 2015
Use contributing.rst that will automatically be picked up by github and shown on PRs and issue reports
orbeckst commentedon Oct 26, 2015
On 23 Oct, 2015, at 23:11, kain88-de wrote:
Thanks, I created #508.