views:

148

answers:

3

For example in Java for Data Transfer Object I use as:

ExampleDTO exampleDTO = new ExampleDTO();

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

A: 

You may want to look at Python Style Guide

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

AJ
This doesn't address the "acronym" issue.
Mark
I think I should have written what @FogleBird gave as answer. +1 to FogleBird.
AJ
+7  A: 

The style most agreeing with PEP-8 would probably be...

example_dto = ExampleDTO()

FogleBird
A: 

Why use acronyms in the first place? I try to avoid them when possible. They obfuscate the code and tend to create code that is hard to browse for quick read. Worst case they bring bugs because of misinterpretation (RndCmp was a Random Compare not a Rounded Complex).

What is DTO? Will it still be used in 2 years? Will every new guy immediately know what it means? In 5 years from now too? Can it be confused with anything else? (Deterministic and Transferable Object?)

The only true (and honest) reason for using acronyms is pure coder laziness. My fun in meetings is to ask about acronyms in variable names and 80% of the times nobody really knows. Even the old guys forget what it meant a couple of years back. We even have some with more than one meanings.

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

The GG
On the other hand, identifiers with acronyms are shorter than identifiers with everything spelled out, which is a considerable advantage.
David Thornley
-1. Acronyms are used in everyday language. And for a reason: efficiency. Being more verbose just for the sake of not using acronyms would be counter productive. Auto-complete is irrelevant. If I use the term DTO in normal language, deviating from that acronym in code would make it less readable, not just more to type.
FogleBird
That said, "DTO" is a painful sight in Python, a clear indication of a Java programmer who is lost. :)
FogleBird
Since I do not know what DTO means (I made it up), I have absolutely no idea what you mean by "a clear indication of a Java programmer who is lost", and thus you are making my point. The free dictionary has more than 60 definition for this acronym.
The GG
"Being more verbose just for the sake of not using acronyms would be counter productive". In what way? Typing a few more characters? Compare this to the many minutes lost for years to come when the new guy will encounter it. For me its about respecting your co-workers.
The GG