473,830 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Request for help on naming conventions

Are there any useful naming conventions for modules, classes and functions?

For instance, should I name functions as verbs and classes as nouns?

eg
class Transformer():
pass

def transform():
do_stuff

What about the module name? transformations .py or transform.py?

What do people do with their own code? Do folks find that being
consistent helps them remember what is what, or do you name objects
whatever feels right at the time?
--
Steven.

Jul 19 '05 #1
2 3044
Steven D'Aprano wrote:
Are there any useful naming conventions for modules, classes and
functions?

For instance, should I name functions as verbs and classes as nouns?

eg
class Transformer():
pass

def transform():
do_stuff

What about the module name? transformations .py or transform.py? You probably want to read the PEP 8, "Style Guide for Python Code":
http://www.python.org/peps/pep-0008.html

What do people do with their own code? Do folks find that being
consistent helps them remember what is what, or do you name objects
whatever feels right at the time?

Naming convention are mostly a matter of personal taste (unless you are
working in a larger team, where there are some official conventions that
must be followed). So I would say the 'feels right' is the most important
factor.

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Jul 19 '05 #2
On Monday 13 June 2005 03:59 am, Steven D'Aprano wrote:
Are there any useful naming conventions for modules, classes and functions?

For instance, should I name functions as verbs and classes as nouns?


Hmm. Okay, here's a few I use:

Classes are generally: Capitalized or CapWords and I use nouns.
Unless it's a "mix-in" in which case, I use adjectives. This mirrors
usage in the Zope sources, BTW.

Method names are either: funkyCaps (Zope uses this) or
lower_case_with _underscores.

I use verb names for methods and functions with very few exceptions.

I use nouns or occasionally adjectives for attributes.

Constants or enumeration values are ALLCAPS or ALL_CAPS, and
usually I define them within a namespace with a descriptive, all lower
case name (a trivial class). The enumeration is usually abbreviated,
but would be an adjective, e.g.:

color.RED

I use *plural* names for lists and tuples, but singular names for
mappings. This is so that I can use the singular in the loop:

for book in books:
pass

But I use single character variables in list comprehensions (and
generators, except I haven't used them yet):

late_books = [b for b in books if b.duedate < datetime.now()]

I also use single-character names in highly mathematical code:

def dot_product(a,b ):
return a.x*b.x + a.y*b.y + a.z*b.z

But if a variable is going to be used more than about 20 lines
away from where it is defined, I use a descriptive word instead.

I like to use Capital or CapWords for modules, too, although I'm
beginning to wonder about that practice.

I really hate redundancy like this:

Topic.create_to pic()

and usually prefer:

Topic.create()

which of course means, I have to qualify things a lot in my code.
This has never been an issue, but if it did, I would just introduce
an intermediary like this ("_" for "."):

Topic_create = Topic.create
After that, it's kind of case-by-case. Do read PEP 8, too, of
course.

--
Terry Hancock ( hancock at anansispacework s.com )
Anansi Spaceworks http://www.anansispaceworks.com

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
320
by: Cristof Falk | last post by:
I wanted to get a feel. The documentation gives naming conventions for public/protected members. Is this truly widely adopted? And what about using the same conventions for private members and variables? My coding preference is to use this everywhere (banish Hungarian and follow the capitalization rules) but I need to sell it to team members.
7
2490
by: cmiddlebrook | last post by:
Hi there, I keep finding myself getting inconsistent with naming conventions for things like member variables, class names etc and I just want to find something that suits me and stick to it. I am wondering if there are any naming conventions around that are deemed suitable by the general C++ community. I have googled around and I can't find much - mostly long lists of hungarian-like prefixes which is not really what I'm after.
1
6553
by: clintonG | last post by:
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and so on? Any referrals to resources that discuss or document XML Naming Conventions? -- <%= Clinton Gallagher, "Twice the Results -- Half the Cost" Architectural & e-Business Consulting -- Software Development NET...
4
7151
by: Mark Broadbent | last post by:
stupid question time again to most of you experts but this is something that continually bothers me. I am trying to get into the habit of naming variables and controls in an assembly as per convensions. The thing is that Ive never really get the full reference to check against. Ive seen a couple of articles, but there always seems to be a bit missing. I also always seem to run into conflicting convensions both in code samples themselves...
5
6178
by: rastaman | last post by:
Hi all, I know of the existence of Object Naming Conventions for Visual Basic 6. Now I'm reading some books about VB .NET, but the names used for the objects are button1, picturebox1, etc. I wonder if I can use the same naming conventions as for VB6 ? If so, what about the names for the new objects in .NET. Kind regards rastaman
4
5453
by: Patrick | last post by:
what are the general naming conventions for vb.net controls. esp txtUserName, lblPassword, btnSubmit What are the prefixes for the controls???? I've tried to search hi and low on the net, but in vain. I'd much appreciate it if someone could guide me with regards to this. All i need are standards for me to follow by my self. Cuz i'm finding it difficult to make my own darn standards.
9
3811
by: kevininstructor | last post by:
Greetings, I am in the process of creating naming conventions for VB.NET controls i.e. CheckBox -> chkShowThisOnStartup ListBoxt -> lstSomeList What I am looking for other developers input for Window.Form controls and what they are using for naming controls.
35
12201
by: Smithers | last post by:
Is it common practise to begin the name of form classes with "frm" (e.g., frmOneForm, frmAnotherForm). Or is that generally considered an outdated convention? If not "frm" what is a common or recommended practise? Thanks.
1
801
by: Philipp Post | last post by:
Marcello, Not a big surprise as naming conventions have a lot to do with personal prefernces. There are a lot of threads in comp.databases and the other database groups. Just do a search for "naming conventions" in the groups. In my oppinion one of the good conventions is presented by Joe Celko in "SQL Programming Style". I would suggest reading it and pick up
0
10774
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10489
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7746
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6950
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.