473,698 Members | 2,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7796
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_word s 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
6711
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: class Foo { public: void somePublicMemberFunction(); protected:
7
2477
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.
4
7145
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...
14
3132
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... (both are "Pascal Case" with no leading or trailing qualifiers). For example... I'll be modelling something, e.g. a computer, and I'll
0
1743
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 Naming Convention". It's a bit of a long post, but I've spent the past few days on perfecting this, finally came to the conclusion that maybe I went a bit overboard with it, almost willing to just say "the @#$ with it" but I didn't want to let it...
10
17778
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 naming convention based on the Windows Forms events. Can someone let me know if this convention is standard,
6
4070
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 practices for naming my objects? I currently have all my type classses simply called "JobSummaryClass" or "JobDetailsClass". These classes simply contain the public properties and the get/set functions for the object. Is this an appropriate naming...
114
7842
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 any comments. --
35
12185
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.
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
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
9031
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...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
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
4372
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
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2007
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.