473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Generator naming convention?

I use generators a lot. E.g.
def gen_words(text)
... parse text ...
yield each word in text

for word in gen_words(text):
print word
I don't like the name gen_xxx() very much. Looking for some inspiration
to name generators. Here are some of my ideas:

enumerate_words
gen_words
generate_words
parse_words
walk_words

Any idea? Do you have a naming convention for generators?

wy

Jun 28 '06 #1
5 7727
au******@gmail.com schrieb:
I use generators a lot. E.g.
def gen_words(text)
... parse text ...
yield each word in text

for word in gen_words(text):
print word
I don't like the name gen_xxx() very much. Looking for some inspiration
to name generators. Here are some of my ideas:

enumerate_words
gen_words
generate_words
parse_words
walk_words

Any idea? Do you have a naming convention for generators?


No. From my POV, a generator is not different from any other method
returning a list. I don't care if the implementation is

def words():
return ["dies", "ist", "das", "Haus", "vom", "Nikolaus"]

or

def words():
for w in ["dies", "ist", "das", "Haus", "vom", "Nikolaus"]:
yield w
Regards,

Diez
Jun 28 '06 #2
au******@gmail.com a écrit :
I use generators a lot. E.g.
def gen_words(text)
... parse text ...
yield each word in text

for word in gen_words(text):
print word
I don't like the name gen_xxx() very much.
Nor do I.
Looking for some inspiration
to name generators. Here are some of my ideas:

enumerate_words
gen_words
generate_words
parse_words
walk_words

Any idea? D
Any of these names have different (somewhat implied) semantic to me. I'd
expect enunmerate_words to yield (order, word) pairs, parse_words to
yield tokens, walk_words to traverse a tree of words, etc

As you see, this is much about what it does than what it is. And FWIW,
do you prefix function names s with fun_ ?
you have a naming convention for generators?


No.

Jun 28 '06 #3
> Any idea? Do you have a naming convention for generators?

Sometimes I use the prefix 'iter', like dictionaries have .items() and
..iteritems(). sometimes I use 'x', like range() vs. xrange(). You
could simply use 'i' like some of the functions in the iteritems module
(imap(), izip(), etc). I guess it depends on the project, what you're
doing, your mood at the moment, and the alignment of Jupiter and
Mercury in Aquarius.

Jun 28 '06 #4
iter- clicks for me, thanks :)

wy
infidel wrote:
Any idea? Do you have a naming convention for generators?


Sometimes I use the prefix 'iter', like dictionaries have .items() and
.iteritems(). sometimes I use 'x', like range() vs. xrange(). You
could simply use 'i' like some of the functions in the iteritems module
(imap(), izip(), etc). I guess it depends on the project, what you're
doing, your mood at the moment, and the alignment of Jupiter and
Mercury in Aquarius.


Jun 28 '06 #5
au******@gmail.com wrote:
I use generators a lot. E.g.
def gen_words(text)
... parse text ...
yield each word in text

for word in gen_words(text):
print word
I don't like the name gen_xxx() very much. Looking for some inspiration
to name generators. Here are some of my ideas:

enumerate_words
gen_words
generate_words
parse_words
walk_words

Any idea? Do you have a naming convention for generators?


If it's not a short one where you can see the whole body immediately,
I think it's more important to mention the generator-ness in the
docstring.

Georg
Jun 29 '06 #6

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

Similar topics

27
by: Derek | last post by:
The company where I work uses a naming convention that I have never used before. They use mixed-case letters for public member functions, but lower-case with underscores for the rest, like this:...
7
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...
4
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...
14
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them......
0
by: Carl Colijn | last post by:
Hi all, Disclaimer: before I might trigger your "let's start a holy war!" button, I'd like to say I'm not intended to; I just post this message to get some input and not to promote "Yet Another...
10
by: jjkboswell | last post by:
I'm trying to pin down a good naming convention for the 3 things required to implement an event. You need: 1) a delegate 2) an event 3) an event handler Below is my understanding of a...
6
by: dm1608 | last post by:
I'm relatively new to ASP.NET 2.0 and am struggling with trying to find the best naming convention for the BAL and DAL objects within my database. Does anyone have any recommendations or best...
114
by: Jonathan Wood | last post by:
I was just wondering what naming convention most of you use for class variables. Underscore, "m_" prefix, camel case, capitalized, etc? Has one style emerged as the most popular? Thanks for...
35
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.