Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to abbreviate dimension following the PEP8 rules?

I must add a function for creating 3D textures. I am using snail case in the entire module.

My choices are:

def texture_3d(...):
    pass

def texture_3D(...):
    pass

def texture3D(...):
    pass

What should be the name of the function?

I am not interested in opinions: which one looks better. I need a few references to other modules to see the best practice.

Please mention at least 1 module having similar functions.

like image 504
Szabolcs Dombi Avatar asked Dec 08 '22 17:12

Szabolcs Dombi


2 Answers

PEP 8 states lowercase with underscore separation between words for function names. Now, because it seems opinionated if 3d/3D is an actual word, you'll get conflicts between the names texture_3d and texture3d (with d being lowercase).

Looking at a number of numpy functions, for example, lagval3d, laggrid3d, hermegrid3d the name texture3d looks like a good choice.

Searching for similar names in the matplotlib docs yields a mixed result between <name>3d and <name>_3d.

In short, both these names seem to be accepted, based on two major packages. Boils down to personal choice between the two.

like image 116
Dimitris Fasarakis Hilliard Avatar answered Dec 11 '22 10:12

Dimitris Fasarakis Hilliard


Rather than depending on mere human opinion, perhaps we could ask the horse? (As in 'getting it from the horse's mouth'.) In other words, use pylint.

I modified your code so that it would generate fewer messages.

''' some information here'''

def texture_3d(parameters):
    ''' a docstring'''
    return parameters

def texture_3D(parameters):
    ''' a docstring'''
    return parameters

def texture3D(parameters):
    ''' a docstring'''
    return parameters

The results of pylint were:

************* Module temp
C:  7, 0: Invalid function name "texture_3D" (invalid-name)
C: 11, 0: Invalid function name "texture3D" (invalid-name)

------------------------------------------------------------------
Your code has been rated at 6.67/10 (previous run: 5.00/10, +1.67)

Which just leaves the option texture_3d.

like image 20
Bill Bell Avatar answered Dec 11 '22 10:12

Bill Bell