method names nounVerb or verbNoun
Wanderer
wanderer at dialup4less.com
Mon Feb 8 10:24:32 EST 2010
On Feb 5, 5:21 pm, Wanderer <wande... at dialup4less.com> wrote:
> On Feb 5, 4:53 pm, Chris Rebert <c... at rebertia.com> wrote:
>
>
>
> > On Fri, Feb 5, 2010 at 1:49 PM, Wanderer <wande... at dialup4less.com> wrote:
> > > On Feb 5, 3:26 pm, Chris Rebert <c... at rebertia.com> wrote:
> > >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer <wande... at dialup4less.com> wrote:
> > >> > Which is the more accepted way to compose method names nounVerb or
> > >> > verbNoun?
>
> > >> > For example voltageGet or getVoltage? getVoltage sounds more normal,
> > >> > but voltageGet is more like voltage.Get. I seem to mix them and I
> > >> > should probably pick one way and stick with it.
>
> > >> Use properties[1] and just call it `voltage`. Python is not Java [2];
> > >> explicit getters/setters are unpythonic.
>
> > >> [1]http://docs.python.org/library/functions.html#property
>
> > > Maybe I'm not using Get right either. I'm wrapping functions.
>
> > > def AbbeGet(self, Lens):
> > > """
> > > Get the Abbe Number V for the material
> > > where
> > > V = (Nd - 1)/(Nf - Nc)
> > > where the Index of Refractions are
> > > Nd at the Fraunhofer D line 0.5892um
> > > Nf at the Fraunhofer F line 0.4861um
> > > Nc at the Fraunhofer C line 0.6563um
> > > """
>
> > > Nd = Lens.Mat.NtGet(0.5892)
> > > Nf = Lens.Mat.NtGet(0.4861)
> > > Nc = Lens.Mat.NtGet(0.6563)
>
> > > if (Nf - Nc) != 0:
> > > V = (Nd - 1)/(Nf - Nc)
> > > else:
> > > V = 1e6
>
> > > return V
>
> > This isn't even really a method; you don't refer to "self" in the body
> > at all. Why isn't it just a function?
>
> > Cheers,
> > Chris
> > --http://blog.rebertia.com
>
> Okay, I guess it should be a function called abbe() instead of a
> method called AbbeGet(). That should solve the problem of trying to
> remember whether I called it GetAbbe or AbbeGet.
>
> Thanks
Actually I decided it still should be a method, just not of doublet
but of Lens. so the calls change from
V1 = self.AbbeGet(Lens1)
V2 = self.AbbeGet(Lens2)
V1 = self.Lens1.abbe()
V2 = self.Lens2.abbe()
More information about the Python-list
mailing list