claird / PyPDF4

A utility to read and write PDFs with Python
obsolete-https://pythonhosted.org/PyPDF2/
Other
328 stars 61 forks source link

Naming style conventions for variable and function names #12

Closed acsor closed 5 years ago

acsor commented 5 years ago

PEP 8 recommends a list of nomenclature conventions for variable and function names:

Function names should be lowercase, with words separated by underscores as necessary to improve readability.

Variable names follow the same convention as function names

but for what I've seen, most of the project names have adopted the lower camelCase in the context of variables and functions/methods:

$ grep -iRP "def\s[a-zA-Z0-9]+_"
Sample_Code/makesimple.py:19:def make_pdf_file(output_filename, np):
Tests/test_filters.py:43:    def test_expected_results(self):
Tests/test_filters.py:58:    def test_unsupported_predictor(self):
Tests/test_filters.py:89:    def test_expected_results(self):
Tests/test_filters.py:121:    def test_no_eod(self):
Tests/test_filters.py:137:    def test_encode_decode(self):
Tests/test_filters.py:164:    def test_with_overflow(self):
Tests/test_filters.py:179:    def test_five_zero_bytes(self):
Tests/test_filters.py:207:    def test_write_code(self):
Tests/test_filters.py:233:    def test_encode_decode(self):
Tests/test_pdf.py:20:    def test_file_load(self):
Tests/test_pdf.py:50:    def test_jpeg_image(self):
Tests/test_pdf.py:79:    def test_properties(self):
Tests/test_pdf.py:102:    def test_add(self):
Tests/test_pdf.py:120:    def test_overwrite(self):
Tests/test_pdf.py:136:    def get_javascript_name(self):
PyPDF4/pagerange.py:98:    def to_slice(self):
PyPDF4/pagerange.py:129:def parse_filename_page_ranges(args):
PyPDF4/generic.py:278:    def as_numeric(self):
PyPDF4/generic.py:296:    def as_numeric(self):
PyPDF4/generic.py:474:    def get_original_bytes(self):
PyPDF4/generic.py:552:    def raw_get(self, key):
PyPDF4/generic.py:1263:def encode_pdfdocencoding(unicode_string):
PyPDF4/generic.py:1278:def decode_pdfdocencoding(byte_array):
PyPDF4/pdf.py:2099:                def used_before(num, generation):
PyPDF4/xmp.py:333:    def custom_properties(self):
Scripts/pdfcat:30:def parse_args():

Those above are the relatively few occurrences where the snake case style has been preferred.

I propose, as PEP 8 further specifies in

mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.

to translate and maintain the name of variables (including function parameters) and functions to the lower camelCase style.

Classes are in line with PEP 8 specifications, but possibly not the module and packages names:

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability.

so in case of PyPDF4, we should have pypdf4. But I don't know how much worth is the expense in effort to rename the module name, although the latter looks way more standard and pleasing to the eyes.

xilopaint commented 5 years ago

Class Names

Class names should normally use the CapWords convention.

The naming convention for functions may be used instead in cases where the interface is documented and used primarily as a callable.

Note that there is a separate convention for builtin names: most builtin names are single words (or two words run together), with the CapWords convention used only for exception names and builtin constants.

acsor commented 5 years ago

There is just an occurrence or a few more of functions with the snake_case style, but apparently PR #14 closes this.