kbgg / qgis-stac-browser

Plugin for QGIS to browse and download assets from STAC APIs
Apache License 2.0
26 stars 9 forks source link

Project style guide discussion #65

Open suricactus opened 5 years ago

suricactus commented 5 years ago

I'm creating this issue for discussion about the style guide in the project, that has to be developed.

I would suggest thinking carefully before you decide to switch to one style or another. I've checked the QGIS repo and even there is no consistency, for example here. I've checked the top most downloaded plugins about camelOrPascalCase vs pep8 recommendation: Use the function naming rules: lowercase with words separated by underscores as necessary to improve readability.. The conclusions from my investigations are: I see a lot of diversity :) . Either lack of consistency or one of the two styles is used. However, it seems there is a little preference towards QT style.

IMHO when dealing with QGIS/QT, it's better to follow their style guide, when everything is depending so much on them. Otherwise mixing is inevitable in the same file. For lib files that are completely separate and independent (therefore might be reused outside the current project), I would use the PEP8 recommendation. PEP8 is not a religious book, even python core libraries break the style guide: logging.getLogger(name).

As for PEP484, I see that in the beginning, the syntax might seem a bit funky to people who are not fully in the CS field. However, in the long term, I think it pays off as smart and easy documentation. Even for beginners, who often use IDEs, can get type checking for free, therefore making it easier to contribute with fewer bugs. PEP484 is a relatively new feature in the Python world (v3.5), QGIS supports Python 3 since Feb 2018 and it's understandable why it's not widely adopted in the community yet. So at least for separate, completely independent files, I would suggest to use it.

As a short summary, I would suggest the following convention.

Of course, all of this is my subjective opinion and it is based on writing and investigating a few public and private QGIS plugins. Feel free to disagree but I think it's a good starting point for a discussion.

# ./utils.py
def reverse_msg(msg: str):
    return msg[::-1]

# ./controllers/deals_with_ui.py

from QtWidgets import QDialog

from ..utils import reverse_msg

class RandomDialog(QDialog):
    def showReversedMsgDialog(self, msg: text = '!ymmuD') -> None:
        importantLabel = self.widgetIdLabel
        importantLabel.setText(reverse_msg(msg))
        importantLabel.clicked.connect(self._onImportantLabelClicked)

    def _onImportantLabelClicked(self) -> None:
        importantLabel.setVisible(False)