472,328 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Alternative constructors naming convention

Hi,

Is there a naming convention regarding alternative constructors? ie
static methods where __new__ is called explicity. I use lower_case for
methods in general, but thought maybe CamelCase would be better for
alternative contstructors to distinguish them from methods...

So which is better?

c = Color.FromHtml(r, g, b)

c = Color.from_html(r, g, b)
Will McGugan
--
http://www.willmcgugan.com

Oct 11 '06 #1
3 2499
Will McGugan wrote:
Hi,

Is there a naming convention regarding alternative constructors? ie
static methods where __new__ is called explicity. I use lower_case for
methods in general, but thought maybe CamelCase would be better for
alternative contstructors to distinguish them from methods...
Well... They are still methods, aren't they ?-)

I don't remember any specific guideline, but FWIW, dict.from_keys() is
an "alternative constructor".

My 2 cents.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Oct 11 '06 #2
Will McGugan wrote:
Is there a naming convention regarding alternative constructors? ie
static methods where __new__ is called explicity.
Are you really using staticmethod and calling __new__? It's often much
easier to use classmethod, e.g.::

class Color(object):
...
@classmethod
def from_html(cls, r, g, b):
...
# convert r, g, b to normal constructor args
...
# call normal constructor
return cls(...)

And FWIW, I use lower_with_underscores for alternate constructors, not
CamelCase.

STeVe
Oct 11 '06 #3
Steven Bethard wrote:
Are you really using staticmethod and calling __new__? It's often much
easier to use classmethod, e.g.::

class Color(object):
...
@classmethod
def from_html(cls, r, g, b):
...
# convert r, g, b to normal constructor args
...
# call normal constructor
return cls(...)
I could use that for some things, but often I can avoid an intermediate
step by bypassing the class constructor altogether...
And FWIW, I use lower_with_underscores for alternate constructors, not
CamelCase.
Seems to be the consensus. I think I'll stick_to_it!
Oct 12 '06 #4

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...
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...
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...
3
by: Aaron Watters | last post by:
A C# question about constructors/static methods and inheritance: Please help me make my code simpler! For fun and as an exercise I wrote somewhat...
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...
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...
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. ...
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...
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...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.