How to name a variable with an abbreviation?

For example, in Java for a data transfer object, I use like:

ExampleDTO exampleDTO = new ExampleDTO();

      

So, if I'm following PEP 8 (lower_case_with_underscores), what naming convention should I use for similar ones in Python?

+2


a source to share


3 answers


The style most consistent with PEP-8 is likely to be ...



example_dto = ExampleDTO()

+10


a source


You can take a look at the Python Style Guide



I personally use camelCase for variables and _ (underscore) separated by method names.

0


a source


Why use acronyms in the first place? I try to avoid them whenever possible. They obfuscate the code and tend to create code that is difficult to view and read quickly. In the worst case, they bring errors due to misinterpretation (RndCmp was a random comparison, not a rounded complex).

What is DTO? Will it be used in another 2 years? Will every new guy know immediately what this means? After 5 years? Is there anything else to confuse him? (Deterministic and portable object?)

The only true (and honest) reason for using acronyms is for sheer coded laziness. My joy in meetings is to ask about abbreviations in variable names and 80% of the time nobody knows. Even the old guys forget what that meant a couple of years ago. We even have some with more than one meaning.

As of today, a great IDE (??) with autocomplete variable names, laziness is a very bad reason to keep them around. From experience you cannot prevent them, but they should always be questioned.

-2


a source







All Articles