Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'example:': 0.03; 'string.': 0.04; 'subject:Python': 0.05; 'float': 0.05; '"the': 0.07; 'emulate': 0.07; 'purpose.': 0.07; 'see.': 0.07; 'variable,': 0.07; 'python': 0.09; '(it': 0.09; 'defined,': 0.09; 'ide': 0.09; 'none.': 0.09; 'overwrite': 0.09; 'tuple': 0.09; 'useless': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'thread': 0.11; 'language': 0.14; 'skip:f 30': 0.15; '"x"': 0.16; "'cause": 0.16; '*always*': 0.16; 'c):': 0.16; 'general.': 0.16; 'notation,': 0.16; 'overwriting': 0.16; 'quadratic': 0.16; 'read?': 0.16; 'sense,': 0.16; 'wait.': 0.16; 'string': 0.17; 'wrote:': 0.17; 'integer': 0.17; 'pfxlen:0': 0.17; 'string,': 0.17; 'widely': 0.17; 'code.': 0.20; 'variable': 0.20; 'email addr:gmail.com>': 0.20; 'parameters': 0.20; 'question.': 0.20; 'skip:" 30': 0.20; 'bit': 0.21; 'init': 0.22; 'suddenly': 0.22; 'cc:2**0': 0.23; 'programming': 0.23; '>': 0.23; 'references': 0.23; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'url:wiki': 0.26; 'converting': 0.27; 'then.': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; '0.5': 0.29; 'container': 0.29; 'context,': 0.29; 'url:wikipedia': 0.29; 'convert': 0.29; 'starts': 0.29; '"the': 0.29; 'skip:& 10': 0.29; "i'm": 0.29; 'code': 0.31; 'skip:- 10': 0.32; 'could': 0.32; 'comments': 0.33; 'says': 0.33; 'int': 0.33; 'null': 0.33; 'problem': 0.33; 'equal': 0.33; 'likely': 0.33; 'skip:& 20': 0.33; 'that,': 0.34; "can't": 0.34; 'received:google.com': 0.34; 'doing': 0.35; 'something': 0.35; 'there': 0.35; 'serve': 0.36; 'but': 0.36; 'url:org': 0.36; 'method': 0.36; 'useful': 0.36; 'skip:p 20': 0.36; 'two': 0.37; 'why': 0.37; 'previous': 0.37; 'subject:: ': 0.38; 'comment': 0.38; 'easier': 0.38; 'supports': 0.38; 'url:en': 0.38; 'called': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'help': 0.40; 'your': 0.60; 'days': 0.60; 'you.': 0.61; 'first': 0.61; 'is.': 0.62; 'helps': 0.63; 'different': 0.63; 'more': 0.63; 'results': 0.65; 'lose': 0.71; 'obvious': 0.71; 'saw': 0.75; '"".': 0.84; '2013': 0.84; 'determinant': 0.84; 'why?': 0.84; 'hungarian': 0.91; 'write:': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=d8p1T4vimHr7sFzseKywQ5j6UXv8FdxzyNTD7EV9VzM=; b=BxLOi6+WIE0ncUVL/UxEM3wCAn4UWsGmM89qjSqEPQHmu0DMSSA9avlQd7EyhPGBaf tFwOVErNeqDmuAdi0bImwNQRh17dHnM4jhPWqNIsYXEpW22cRAu0FG8vTHc6P6/1Daqw ewAWVDPKj4Gu7/NpPaVgdzdM1/2pv+2Aob1gmgSCHTT9CpbUYF9IVDLsKaQPhcWbSOUk 4+oOI8IbTn/GkvZ9Jfaw84AZ7L0PWUgOTkPUHvlYnZp+ylhJVJyzxPiAVqAKVdN6IdC1 iXTy9C8PXQDAbePuGrt+1Ra2DAl+IxawQbpJynSOYoMaB8oC3C0CjUlGqfHTChgCp8f2 cEtg== X-Received: by 10.112.30.198 with SMTP id u6mr3679913lbh.9.1361741772081; Sun, 24 Feb 2013 13:36:12 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <5a3bf25b-a08b-4084-a940-e1fd05a1045d@googlegroups.com> References: <5127848B.1060004@gmail.com> <928d2cf7-728b-4f35-b8c9-4c9b958507e5@googlegroups.com> <8eadd52c-d533-4333-8c7f-7bf3a6d7b046@googlegroups.com> <9p1ii899tkalvfd1cl7sneoqa9t1cqh4oj@invalid.netcom.com> <5129482F.3080402@gmail.com> <512a5199$0$29998$c3e8da3$5496439d@news.astraweb.com> <5a3bf25b-a08b-4084-a940-e1fd05a1045d@googlegroups.com> From: Joshua Landau Date: Sun, 24 Feb 2013 21:35:31 +0000 Subject: Re: Python Newbie To: piterrr.dolinski@gmail.com Content-Type: multipart/alternative; boundary=f46d04016b2199ca5204d67f3645 Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 275 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361741780 news.xs4all.nl 6934 [2001:888:2000:d::a6]:37212 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39800 --f46d04016b2199ca5204d67f3645 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 24 February 2013 19:29, wrote: > Hi. Steve, I don't know where you have been over the past couple of days > but it is widely known (if the thread title is any indication) that I am > indeed very new to Python, but not new to programming in general. > > To give a bit of background where I found __str__, I am using a Python ID= E > called PyScripter. Its Intellisense is full of methods starting and endin= g > with "__", hence the question. > > Regarding Hungarian notation, I don't use it in any other language but > Python and JS. Call it poor, but it helps me to remember what type a > variable is. If you can't remember what type a variable is, you're doing something incorrectly. > The redundant comments serve the same purpose. To help you remember the type of the variable? > intX =3D 32 # decl + init int var How is it not obvious that "intX" is an integer *without* the comment? > X =3D 32 How is it not obvious that X is an integer? > intX_asString =3D None # decl + init with NULL string var How is it not obvious that intX_asString is an integer (it starts with "int", duh"... oh wait) The comment says it's the NULL string, so it's "". F*ck. It's None. Why? No idea. > intX_asString =3D intX.__str__ () # convert int to string Wait. So why'd you write the previous line? Just write: > X_as_string =3D str(X) 'Cause "str" *always* returns a string. So it's a string. How is that not obvious? But then, what's the context? "X" is a *useless* name. Why are you converting X to a string? I have no idea. The problem with the code isn't that you could be overwriting "X". The problem is that your code is contradictory, pretends it's C, has useless names and doesn't try to be readable. > As for "pointless predeclaration", it helps me know where in the code I > first started using the variable, so I know there are no references to it > before then. > Why? Why can't you overwrite old variables? Why can't a variable change type? If your functions are so large that you're likely to lose track of what's defined, you have a different problem indeed. For example: def floatA_floatB_floatC_to_tupleR(floatA, floatB, floatC): # decl with floatA, floatB, floatC parameters floatD =3D None # decl + init with NULL float var floatD =3D ((floatB ** 2) - (4 * floatA * floatC)) # set to B=C2=B2 - 4= AC floatD =3D floatD ** 0.5 # set to =E2=88=9AfloatD floatR1 =3D None # decl + init with NULL float var floatR1 =3D (((- floatB) + floatD) / (2 * floatA)) # set to (-B+D)/(2A) floatR2 =3D None # decl + init with NULL float var floatR2 =3D (((- floatB) - floatD) / (2 * floatA)) # set to (-B-D)/(2A) return (floatR1, floatR2) Versus def solve_quadratic(a, b, c): """Solve a quadratic equation of the form ax=C2=B2 + bx + c =3D 0 The result will be a tuple of the two results; the results can be equal if the determinant is 0. This supports imaginary results for if the determinant is negative.""" # The method used is the quadratic equation: # http://en.wikipedia.org/wiki/Quadratic_equation # b=C2=B2 - 4ac determinant =3D b**2 - 4*a*c # =C2=B1=E2=88=9A(b=C2=B2 - 4ac) sqrt_determinant =3D determinant ** 0.5 squareroots =3D sqrt_determinant, -sqrt_determinant # -b =C2=B1 =E2=88=9A(b=C2=B2 - 4ac) fraction_tops =3D [(-b + d) for d in squareroots] results =3D [top/(2*a) for top in fraction_tops] return results Which is easier to read? Reading through it you don't just suddenly forget what the type of "determinant" is (which must be a number because it's a determinant) or "results" (which is a container since it's plural). The names tell you. The useful comments such as "The method used is..." and "=C2=B1=E2=88=9A(b= =C2=B2 - 4ac)" give you context, too, which is a lot more than can be said of "floatA_floatB_floatC_to_tupleR". For that, I tried to emulate what I saw in your code. I'm not a good programmer. But because of that the code I write makes sense, so I can understand it. Tell the reader what they want to know, not what they see. --f46d04016b2199ca5204d67f3645 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

= On 24 February 2013 19:29, <piterrr.dolinski@gmail.com> wrote:
Hi. = Steve, I don't know where you have been over the past couple of days bu= t it is widely known (if the thread title is any indication) that I am inde= ed very new to Python, but not new to programming in general.

To give a bit of background where I found __str__, I am using a Python IDE = called PyScripter. Its Intellisense is full of methods starting and ending = with "__", hence the question.

Regarding Hungarian notation, I don't use it in any other language but = Python and JS. Call it poor, but it helps me to remember what type a variab= le is.

If you can't remember what= type a variable is, you're doing something incorrectly.
=C2=A0
The redundant comments serve the same pur= pose.

To help you remember the type of the variable?

> intX =3D 32 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# decl + init int var
How is it not obvious that "intX" is an integer *witho= ut* the comment?

> X =3D 32
How is it not obvious that X is an integer?

> intX_asStr= ing =3D None =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # decl + init= with NULL string var
How is it not obvious that int= X_asString is an integer (it starts with "int", duh"... oh w= ait)

The comment says it's the NULL string, = so it's "". F*ck.

It'= ;s None. Why? No idea.

> intX_asString =3D intX.__= str__ () =C2=A0 =C2=A0# convert int to string
Wait. So why'd you wr= ite the previous line?

Just writ= e:
> X_as_string =3D str(X)
'Cause "str&quo= t; *always* returns a string. So it's a string. How is that not obvious= ?


But then, what's the context?<= /div>

"X" is a *useless* name. Why= are you converting X to a string? I have no idea. The problem with the cod= e isn't that you could be overwriting "X". The problem is tha= t your code is contradictory, pretends it's C, has useless names and do= esn't try to be readable.
=C2=A0
As for "pointless predeclarati= on", it helps me know where in the code I first started using the vari= able, so I know there are no references to it before then.

Why? Why can't you overwrite old= variables? Why can't a variable change type? If your functions are so = large that you're likely to lose track of what's defined, you have = a different problem indeed.


For example:
def floatA_floatB_floatC_to_tupleR(floatA, floatB, floatC): # d= ecl with floatA, floatB, floatC parameters
=C2=A0 =C2=A0 floatD = =3D None # decl + init with NULL float var
=C2=A0 =C2=A0 floatD =3D ((floatB ** 2) - (4 * floatA * floatC)) # set= to B=C2=B2 - 4AC
=C2=A0 =C2=A0 floatD =3D floatD ** 0.5 # set to= =E2=88=9AfloatD

=C2=A0 =C2=A0 floatR1 =3D None # = decl + init with NULL float var
=C2=A0 =C2=A0 floatR1 =3D (((- fl= oatB) + floatD) / (2 * floatA)) # set to (-B+D)/(2A)

=C2=A0 =C2=A0 floatR2 =3D None # decl + init with NULL = float var
=C2=A0 =C2=A0 floatR2 =3D (((- floatB) - floatD) / (2 *= floatA)) # set to (-B-D)/(2A)

=C2=A0 =C2=A0 retur= n (floatR1, floatR2)

Versus

def solve_quadratic(a,= b, c):
"= ""Solve a quadratic equation of the form ax=C2=B2 + bx + c =3D 0<= /div>

The resul= t will be a tuple of the two results; the results can be equal if the deter= minant is 0.
T= his supports imaginary results for if the determinant is negative."&qu= ot;"

# Th= e method used is the quadratic equation:

# b= =C2=B2 - 4ac
d= eterminant =3D b**2 - 4*a*c

# =C2=B1=E2=88=9A(b=C2=B2 - 4ac)
sqrt_determinant = =3D determinant ** 0.5
squareroots =3D sqrt_determinant, -sqrt_determinant

=
# -b =C2=B1 =E2=88=9A(b= =C2=B2 - 4ac)
= fraction_tops =3D [(-b + d) for d in squareroots]

= results =3D [top/(2*a) f= or top in fraction_tops]

retu= rn results

Which is easier to read? Reading = through it you don't just suddenly forget what the type of "determ= inant" is (which must be a number because it's a determinant) or &= quot;results" (which is a container since it's plural). The names = tell you.

The useful comments such as "The metho= d used is..." and "=C2=B1=E2=88=9A(b=C2=B2 - 4ac)" give you = context, too, which is a lot more than can be said of "floatA_floatB_f= loatC_to_tupleR". For that, I tried to emulate what I saw in your code= .

I'm not a good programmer. But because = of that the code I write makes sense, so I can understand it. Tell the read= er what they want to know, not what they see.
--f46d04016b2199ca5204d67f3645--