[Tutor] python_naming_conventions - newbie
Kirk Bailey
idiot1 at netzero.net
Mon Oct 20 01:21:07 EDT 2003
Intresting. I wonder if the Matrix is a wikiwiki?
Rahul Kumar wrote:
> Interestingly, while going through the code of TwistedMatrix I find that
> they use the camelCase. I wonder what Bruce Eckel uses (the Thinking in
> Java guy who has moved to Python).
> I completely agree about consistency over ethics, but just wanted to
> know how the decision was made in the first place.
> Thanks for your answers.
>
> On Sat, Oct 18, 2003 at 11:17:26AM -0400, Erik Price wrote:
>
>>Date: Sat, 18 Oct 2003 11:17:26 -0400
>>Subject: Re: [Tutor] python_naming_conventions - newbie
>>Cc: tutor at python.org
>>To: Rahul Kumar <rahulk at bhartitelesoft.com>
>>From: Erik Price <erikprice at mac.com>
>>X-Mailer: Apple Mail (2.552)
>>
>>
>>On Friday, October 17, 2003, at 01:51 AM, Rahul Kumar wrote:
>>
>>
>>>As someone learning python after several years of working on Java, i am
>>>interested to know why does python follow the
>>>lower_case_with_underscores way of naming methods and variables while
>>>Java follows the MixedCaseWithoutUnderscores.
>>
>>I don't know the answer why, but one of the more important suggestions
>>made by both "Java Elements of Style" and IIRC the Python Style
>>Guidelines is that convention is more important than aesthetics. That
>>is to say, while aesthetics certainly play a role (even in the very
>>choice of a name for a variable), what is more important is to make
>>sure that your naming is consistent with what is conventional for your
>>project. Java happens to have a well-known published style guide that
>>strongly recommends that camelCase be used for variable names and
>>UNDERSCORE_SEPARATORS only be used in [capitalized] constant
>>declarations (static final String FOO).
>>
>>That said, my guess is that the reason why it was originally selected
>>is probably because the extra underscores make the variable names
>>wider. This isn't as much an issue in Python because type and access
>>declarations aren't used, but because you need to declare the access
>>level and type/return type in Java, it ends up making your code lines
>>wider. Just yesterday I wrote this method signature:
>>
>> private Mip mipFromFile(File mipFile)
>>
>>whereas in Python, it could have simply been declared as:
>>
>> def mip_from_file(mip_file):
>>
>>As you can see, the Python version is still shorter even though I've
>>used the underscores as separators.
>>
>>
>>>After writing a couple of py progs, i find myself using the python way
>>>in Java, and i prefer it (used to write C progs this way 10 yrs ago),
>>>and
>>>i need some justification for this, since i am the guy who made the
>>>Java
>>>guidelines for my org 4 years back !
>>
>>In Python I don't really stick to one or the other, but try to go with
>>what seems most logical for the situation. However, in Java my own
>>preference is to simply stick to the official standard simply because
>>when others read my code, that's probably what they'll expect to see.
>>
>>
>>Erik
>>
>
>
--
--
end
Cheers!
Kirk D Bailey
+ think +
http://www.howlermonkey.net +-----+ http://www.tinylist.org
http://www.listville.net | BOX | http://www.sacredelectron.org
Thou art free"-ERIS +-----+ 'Got a light?'-Prometheus
+ kniht +
Fnord.
More information about the Tutor
mailing list