Re: coding style - where to declare variables

2018-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2018 14:39:56 +0300, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Lambda calculus has the concept of a binding operator, which is >> effectively an assignment operator: it takes a variable and a value and >> binds the value to the variable, changing a free variable to a bound >>

Re: coding style - where to declare variables

2018-07-23 Thread Chris Angelico
On Mon, Jul 23, 2018 at 9:39 PM, Steven D'Aprano wrote: > [1] The CPython interpreter uses pointers; the Jython interpreter uses > whatever kind of memory indirection the JVM provides; when I emulate a > Python interpreter using pencil and paper, there's not a pointer in sight > but a lot of copyi

Re: coding style - where to declare variables

2018-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2018 09:22:55 +0300, Marko Rauhamaa wrote: > Dennis Lee Bieber : [...] >> In my world, Java and Python are the ones that are not "common". > > Yes, "boxed" is a Java term. However, the programming pattern of using > dynamic memory and pointers is ubiquitous and ancient: Not t

Re: coding style - where to declare variables

2018-07-23 Thread Marko Rauhamaa
Steven D'Aprano : > Lambda calculus has the concept of a binding operator, which is > effectively an assignment operator: it takes a variable and a value > and binds the value to the variable, changing a free variable to a > bound variable. In other words, it assigns the value to the variable, > j

Re: coding style - where to declare variables

2018-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2018 11:49:37 +0300, Marko Rauhamaa wrote: > People new to Python are unnecessarily confused by talking about names > and binding when it's really just ordinary variables and assignment. It really isn't, not to those people who expect ordinary variables and assignment to be the sa

Re: coding style - where to declare variables

2018-07-23 Thread Ben Bacarisse
Mark Lawrence writes: > On 22/07/18 14:51, Abdur-Rahmaan Janhangeer wrote: >> except local vars >> >> Abdur-Rahmaan Janhangeer >> https://github.com/Abdur-rahmaanJ >> Mauritius >> > > Python doesn't have variables, it has names. I think we should cut beginners (and probably everyone) some slack

Re: coding style - where to declare variables

2018-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2018 20:24:30 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> So let me see if I understand your argument... >> >> - we should stop using the term "binding", because it means >> nothing different from assignment; >> - binding (a.k.a. "assignment") comes from lambda calcul

Re: coding style - where to declare variables

2018-07-23 Thread Frank Millman
"Marko Rauhamaa" wrote in message news:87zhyitjz2@elektro.pacujo.net... People new to Python are unnecessarily confused by talking about names and binding when it's really just ordinary variables and assignment. It seems to be mostly some sort of marketing lingo that seeks to create an air

Re: coding style - where to declare variables

2018-07-23 Thread Marko Rauhamaa
Ben Finney : > Gregory Ewing writes: > >> Marko is asking us to stop using the word "binding" to refer to >> assignment because of the potential confusion with this other meaning. > > That's about as reasonable as my request that we stop using the term > “variable” for what is, in Python, an un-ty

Re: coding style - where to declare variables

2018-07-23 Thread Ben Finney
Gregory Ewing writes: > Marko is asking us to stop using the word "binding" to refer to > assignment because of the potential confusion with this other meaning. That's about as reasonable as my request that we stop using the term “variable” for what is, in Python, an un-typed reference to an obj

Re: coding style - where to declare variables

2018-07-23 Thread Gregory Ewing
Steven D'Aprano wrote: So let me see if I understand your argument... - we should stop using the term "binding", because it means nothing different from assignment; - binding (a.k.a. "assignment") comes from lambda calculus; - which has no assignment (a.k.a. "binding"). No, that's not what

Re: coding style - where to declare variables

2018-07-22 Thread Marko Rauhamaa
Dennis Lee Bieber : > On Mon, 23 Jul 2018 00:08:00 +0300, Marko Rauhamaa > declaimed the following: > >>I Java terms, all Python values are boxed. That's a very usual pattern >>in virtually all programming languages (apart from FORTRAN). > > FORTRAN, C, COBOL, BASIC, Pascal, ALGOL, BCPL, REX

Re: coding style - where to declare variables

2018-07-22 Thread Abdur-Rahmaan Janhangeer
variables here refers to the user experience of a var np, just a link to the thread/s would mark the end of it Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius -- https://mail.python.org/mailman/listinfo/python-list

Re: coding style - where to declare variables

2018-07-22 Thread Mark Lawrence
On 22/07/18 14:51, Abdur-Rahmaan Janhangeer wrote: except local vars Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius Python doesn't have variables, it has names. Please can we avoid a long meaningless thread on this subject as it's been discussed a trillion times befor

Re: coding style - where to declare variables

2018-07-22 Thread Steven D'Aprano
On Sun, 22 Jul 2018 17:50:06 -0400, Dennis Lee Bieber wrote: > On Mon, 23 Jul 2018 00:08:00 +0300, Marko Rauhamaa > declaimed the following: > >>I Java terms, all Python values are boxed. That's a very usual pattern >>in virtually all programming languages (apart from FORTRAN). >> >> > FOR

Re: coding style - where to declare variables

2018-07-22 Thread Steven D'Aprano
On Mon, 23 Jul 2018 00:08:00 +0300, Marko Rauhamaa wrote: > Would you call it binding in this case: > >X[0]["z"] = getit() >X[3]["q"] = X[0]["z"] >X[0]["z"].changeit() It is a binding, but it is not a *name* binding. Since we are talking about name bindings, and comparing/contrastin

Re: coding style - where to declare variables

2018-07-22 Thread Steven D'Aprano
On Sun, 22 Jul 2018 22:50:52 +0300, Marko Rauhamaa wrote: > I wish people stopped talking about "name binding" and "rebinding," > which are simply posh synonyms for variable assignment. Properly, the > term "binding" comes from lambda calculus, whose semantics is defined > using "bound" and "free"

Re: coding style - where to declare variables

2018-07-22 Thread Marko Rauhamaa
Richard Damon : >> On Jul 22, 2018, at 3:50 PM, Marko Rauhamaa wrote: >> I wish people stopped talking about "name binding" and "rebinding," >> which are simply posh synonyms for variable assignment. Properly, the >> term "binding" comes from lambda calculus, whose semantics is defined >> using "

Re: coding style - where to declare variables

2018-07-22 Thread Chris Angelico
On Mon, Jul 23, 2018 at 6:14 AM, Marko Rauhamaa wrote: > While FORTRAN or C couldn't operate on functions like this, an assembly > language program could easily. Simply compose a CPU instruction sequence > on the fly, mark it executable and use the "CALL" opcode to transfer > control to your const

Re: coding style - where to declare variables

2018-07-22 Thread Marko Rauhamaa
Bart : > If you did need one of those others to be variable, then you just assign > it to a variable the rare times you need to do that. For example: > > def fn1(): pass > def fn2(): pass > > fn = fn1 if cond else fn2 > > fn1, fn2 will always be functions. fn will always be a variable, but on

Re: coding style - where to declare variables

2018-07-22 Thread Richard Damon
> On Jul 22, 2018, at 3:50 PM, Marko Rauhamaa wrote: > I wish people stopped talking about "name binding" and "rebinding," > which are simply posh synonyms for variable assignment. Properly, the > term "binding" comes from lambda calculus, whose semantics is defined > using "bound" and "free" var

Re: coding style - where to declare variables

2018-07-22 Thread Marko Rauhamaa
r...@zedat.fu-berlin.de (Stefan Ram): >>Rebinding names is near-universal in programming, but usually names >>that are intended to be rebound, such as variables. > > To someone like me who has grown up with a LISP 1 > this is completely natural. > > |>( SETQ A ( LAMBDA () 'ALPHA )) > |(LAMBDA (

Re: coding style - where to declare variables

2018-07-22 Thread Peter J. Holzer
On 2018-07-22 09:36:13 -0400, Richard Damon wrote: > > On Jul 22, 2018, at 8:48 AM, Sharan Basappa > > wrote: > > > > In other programming languages (e.g. C, C++), as a good practice, > > variables are declared right at the start of the program, There is no "start of the program" in C or C++. I

Re: coding style - where to declare variables

2018-07-22 Thread Abdur-Rahmaan Janhangeer
except local vars Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius -- https://mail.python.org/mailman/listinfo/python-list

Re: coding style - where to declare variables

2018-07-22 Thread Chris Angelico
On Sun, Jul 22, 2018 at 10:48 PM, Sharan Basappa wrote: > In other programming languages (e.g. C, C++), as a good practice, variables > are declared right at the start of the program, irrespective of where it is > normally used. What is the practice in Python? > > I see that, most of the code, d

Re: coding style - where to declare variables

2018-07-22 Thread Richard Damon
> On Jul 22, 2018, at 8:48 AM, Sharan Basappa wrote: > > In other programming languages (e.g. C, C++), as a good practice, variables > are declared right at the start of the program, irrespective of where it is > normally used. What is the practice in Python? > > I see that, most of the code

Re: Coding style in CPython implementation

2017-10-30 Thread Rhodri James
On 28/10/17 19:42, Στέφανος Σωφρονίου wrote: Greetings everyone. I have noticed that in many if conditions the following syntax is used: a) if (variable == NULL) { ... } b) if (variable == -1) { ... } c) if (variable != NULL) { ... } What I wanted to ask is, is there a particular reason for no

Re: Coding style in CPython implementation

2017-10-29 Thread Στέφανος Σωφρονίου
On Monday, October 30, 2017 at 2:35:13 AM UTC+2, ROGER GRAYDON CHRISTMAN wrote: > NOTE: The case in question was never comparing to True; it was comparing to > NULL. > > There is no "No: if x == None" below, because None is not Boolean. > Similarly comparing a pointer to NULL is not the same as

Re: Coding style in CPython implementation

2017-10-29 Thread ROGER GRAYDON CHRISTMAN
NOTE: The case in question was never comparing to True; it was comparing to NULL. There is no "No: if x == None" below, because None is not Boolean. Similarly comparing a pointer to NULL is not the same as comparing it to a Boolean. So I would favor the "Explicit is better than Implicit" in th

Re: Coding style in CPython implementation

2017-10-29 Thread Chris Angelico
On Mon, Oct 30, 2017 at 12:47 AM, Stefan Ram wrote: > =?UTF-8?B?zqPPhM6tz4bOsc69zr/PgiDOo8+Jz4bPgc6/zr3Or86/z4U=?= > writes: >>I guess the following parts from "Zen of Python" apply to this case: > > If we would agree to apply Python rules to C, > then we could also use this excerpt from PEP

Re: Coding style in CPython implementation

2017-10-29 Thread Rick Johnson
On Sunday, October 29, 2017 at 4:00:59 AM UTC-5, Στέφανος Σωφρονίου wrote: [...] > I guess the following parts from "Zen of Python" apply to this case: > > - Beautiful is better than ugly. > - Explicit is better than implicit. > - Simple is better than complex. > - Readability counts. Now go

Re: Coding style in CPython implementation

2017-10-29 Thread Στέφανος Σωφρονίου
On Sunday, October 29, 2017 at 4:18:38 AM UTC+2, Dan Sommers wrote: > On Sat, 28 Oct 2017 16:20:54 -0700, Στέφανος Σωφρονίου wrote: > > > I do believe though that if (!d) is a lot clearer than if (d == NULL) > > as it is safer than falsely assigning NULL in d, by pure mistake. > > Having made my

Re: Coding style in CPython implementation

2017-10-28 Thread Dan Sommers
On Sat, 28 Oct 2017 16:20:54 -0700, Στέφανος Σωφρονίου wrote: > I do believe though that if (!d) is a lot clearer than if (d == NULL) > as it is safer than falsely assigning NULL in d, by pure mistake. Having made my living writing C code for a very long time, I always found if (!d) *harder* to r

Re: Coding style in CPython implementation

2017-10-28 Thread Στέφανος Σωφρονίου
On Saturday, October 28, 2017 at 9:54:30 PM UTC+3, bartc wrote: > On 28/10/2017 19:42, Στέφανος Σωφρονίου wrote: > > Greetings everyone. > > > > I have noticed that in many if conditions the following syntax is used: > > > > a) if (variable == NULL) { ... } > > b) if (variable == -1) { ... } > >

Re: Coding style in CPython implementation

2017-10-28 Thread Ned Batchelder
On 10/28/17 4:26 PM, Stefan Ram wrote: Ned Batchelder writes: On 10/28/17 3:00 PM, Stefan Ram wrote: =?UTF-8?B?zqPPhM6tz4bOsc69zr/PgiDOo8+Jz4bPgc6/zr3Or86/z4U=?= writes: What I wanted to ask is, is there a particular reason for not choosing definition of »NULL«. »NULL« is not part of the

Re: Coding style in CPython implementation

2017-10-28 Thread Ned Batchelder
On 10/28/17 3:00 PM, Stefan Ram wrote: =?UTF-8?B?zqPPhM6tz4bOsc69zr/PgiDOo8+Jz4bPgc6/zr3Or86/z4U=?= writes: What I wanted to ask is, is there a particular reason for not choosing I am not a CPython developer, but here are my 2 cents about the possibilities: if (variable == NULL) { ...

Re: Coding style in CPython implementation

2017-10-28 Thread Chris Angelico
On Sun, Oct 29, 2017 at 5:42 AM, Στέφανος Σωφρονίου wrote: > Greetings everyone. > > I have noticed that in many if conditions the following syntax is used: > > a) if (variable == NULL) { ... } > b) if (variable == -1) { ... } > c) if (variable != NULL) { ... } > > What I wanted to ask is, is ther

Re: Coding style in CPython implementation

2017-10-28 Thread bartc
On 28/10/2017 19:42, Στέφανος Σωφρονίου wrote: Greetings everyone. I have noticed that in many if conditions the following syntax is used: a) if (variable == NULL) { ... } b) if (variable == -1) { ... } c) if (variable != NULL) { ... } What I wanted to ask is, is there a particular reason for

Re: coding style - try, except

2009-02-25 Thread RGK
I'm glad I asked :) Thanks all who posted for your replies, the else-statement is a nice option. Python again comes through to deal with those pesky feelings that something could be better :) Ross. Chris Rebert wrote: Yes. try-except-*else*. try: do_something_1() do_something

Re: coding style - try, except

2009-02-25 Thread Christian Heimes
RGK wrote: > Any input appreciated :) How about: import logging try: # run your function some_function() except Exception: # except only the exceptions you *really* want to catch # at most you should except "Exception" since it doesn't # catch KeyboardInterrupt and SystemExit l

Re: coding style - try, except

2009-02-25 Thread Scott David Daniels
RGK wrote: I'm still learning, so eager to see if there is some community wisdom about use of the try/except structures in this situation try: do something 1 do something 2 do something 3 do something 4 ... do something 25 except: print "Oops something didn't

Re: coding style - try, except

2009-02-25 Thread Peter Otten
Steve Holden wrote: > RGK wrote: >> >> I'm still learning, so eager to see if there is some community wisdom >> about use of the try/except structures in this situation. >> >> I find myself with some potentially risky stuff and wrap it in a >> try/except structure with good functional results, t

Re: coding style - try, except

2009-02-25 Thread Chris Rebert
On Wed, Feb 25, 2009 at 9:36 AM, RGK wrote: > > I'm still learning, so eager to see if there is some community wisdom about > use of the try/except structures in this situation. > > I find myself with some potentially risky stuff and wrap it in a try/except > structure with good functional results

Re: coding style - try, except

2009-02-25 Thread Steve Holden
RGK wrote: > > I'm still learning, so eager to see if there is some community wisdom > about use of the try/except structures in this situation. > > I find myself with some potentially risky stuff and wrap it in a > try/except structure with good functional results, though my code leaves > me a b

Re: Coding style and else statements

2006-08-31 Thread Ben Finney
[EMAIL PROTECTED] writes: > > To my eyes, that's less readable than, and has no benefit over, > > the following: > > > > def foo(thing): > > if thing: > > result = thing+1 > > else: > > result = -1 > > return result I chose this to more clearly

Re: Coding style and else statements

2006-08-31 Thread matt . newville
> To my eyes, that's less readable than, and has no benefit over, the > following: > > def foo(thing): > if thing: > result = thing+1 > else: > result = -1 > return result I wouldn't discount: def foo(thing): result = -1 if thing:

Re: Coding style and else statements

2006-08-31 Thread Ben Finney
Pete Forman <[EMAIL PROTECTED]> writes: > Ben Finney <[EMAIL PROTECTED]> writes: > > > Why not ensure that there is one return point from the function, > > so the reader doesn't have to remind themselves to look for hidden > > return points? > > There will always be more potential return points in

Re: Coding style and else statements

2006-08-31 Thread Pete Forman
Ben Finney <[EMAIL PROTECTED]> writes: > Why not ensure that there is one return point from the function, so > the reader doesn't have to remind themselves to look for hidden > return points? There will always be more potential return points in languages that support exceptions. -- Pete Forma

Re: Coding style and else statements

2006-08-30 Thread Ben Finney
"Carl Banks" <[EMAIL PROTECTED]> writes: > Ben Finney wrote: > > "Carl Banks" <[EMAIL PROTECTED]> writes: > > > def foo(thing): > > > if thing: > > > return thing+1 > > > else: > > > return -1 > > > assert False > > > > To my eyes, that's less readable than, and has no

Re: Coding style and else statements

2006-08-30 Thread Carl Banks
Steve Holden wrote: > Carl Banks wrote: > [...] > > However, I have rare cases where I do choose to use the else (ususally > > in the midst of a complicated piece of logic, where it's be more > > distracting than concise). In that case, I'd do something like this: > > > > def foo(thing): > >

Re: Coding style and else statements

2006-08-30 Thread Carl Banks
Ben Finney wrote: > "Carl Banks" <[EMAIL PROTECTED]> writes: > > > However, I have rare cases where I do choose to use the else > > (ususally in the midst of a complicated piece of logic, where it's > > be more distracting than concise). In that case, I'd do something > > like this: > > > > def f

Re: Coding style and else statements

2006-08-30 Thread [EMAIL PROTECTED]
Tal Einat wrote: > I meant to say that: > > (thing and [thing+1] or [-1])[0] > > is more readable (IMO) than: > > thing != -1 and (thing and thing+1 or -1) or 0 Neither is particularly readable, though I agree that the latter is worse since it has to have the third option ("0") on the end. But I'

Re: Coding style and else statements

2006-08-30 Thread Gabriel Genellina
At Wednesday 30/8/2006 04:47, Tal Einat wrote: I meant to say that: (thing and [thing+1] or [-1])[0] is more readable (IMO) than: thing != -1 and (thing and thing+1 or -1) or 0 Interesting to find how different persons feel "readability" - for me, the later is rather clear (but definitivel

Re: Coding style and else statements

2006-08-30 Thread Tal Einat
Sybren Stuvel wrote: > Tal Einat enlightened us with: > > Actually, the common work-around for this is: > > > > (thing and [thing+1] or [-1])[0] > > > > This works since non-empty lists are always considered true in > > conditional context. This is more generic, and IMO more readable. > > I think

Re: Coding style and else statements

2006-08-30 Thread Ben Finney
"Carl Banks" <[EMAIL PROTECTED]> writes: > However, I have rare cases where I do choose to use the else > (ususally in the midst of a complicated piece of logic, where it's > be more distracting than concise). In that case, I'd do something > like this: > > def foo(thing): > if thing: >

Re: Coding style and else statements

2006-08-29 Thread Steve Holden
Carl Banks wrote: [...] > However, I have rare cases where I do choose to use the else (ususally > in the midst of a complicated piece of logic, where it's be more > distracting than concise). In that case, I'd do something like this: > > def foo(thing): > if thing: > return thing+1 >

Re: Coding style and else statements

2006-08-29 Thread Carl Banks
tobiah wrote: > def foo(thing): > if thing: > return thing + 1 > else: > return -1 > > def foo(thing): > if thing: > return thing + 1 > return -1 > > Obviously both do the same thing. The first is > possibly clearer, while the secon

Re: Coding style and else statements

2006-08-29 Thread Tal Einat
Bruno Desthuilliers wrote: > Sam Pointon a écrit : > > Bruno Desthuilliers wrote: > > > >>foo = lambda thing: thing and thing + 1 or -1 > > > > > > The and ... or trick is buggy (what if thing == -1?) > > Yes, true - Should be: > foo2 = lambda t: t != -1 and (t and t+1 or -1) or 0 > Actually, the

Re: Coding style and else statements

2006-08-28 Thread Bruno Desthuilliers
Sam Pointon a écrit : > Bruno Desthuilliers wrote: > >>foo = lambda thing: thing and thing + 1 or -1 > > > The and ... or trick is buggy (what if thing == -1?) Yes, true - Should be: foo2 = lambda t: t != -1 and (t and t+1 or -1) or 0 > and bad style. Lol. Well, so what about: foo = lambda

Re: Coding style and else statements

2006-08-28 Thread Tal Einat
tobiah wrote: > def foo(thing): > > if thing: > return thing + 1 > else: > return -1 > > def foo(thing): > > if thing: > return thing + 1 > return -1 > > Obviously both do the same thing. The first is > possibly clearer, while the s

Re: Coding style and else statements

2006-08-28 Thread Sam Pointon
Bruno Desthuilliers wrote: > foo = lambda thing: thing and thing + 1 or -1 The and ... or trick is buggy (what if thing == -1?) and bad style. If you -do- want a conditional expression, 2.5 provides one: thing + 1 if thing else -1 No subtle logical bugs, and a good deal more obvious. On the top

Re: Coding style and else statements

2006-08-28 Thread Bruno Desthuilliers
tobiah a écrit : > def foo(thing): > > if thing: > return thing + 1 > else: > return -1 > > def foo(thing): > > if thing: > return thing + 1 > return -1 > > Obviously both do the same thing. The first is > possibly clearer, while the second is more conci

Re: Coding style and else statements

2006-08-28 Thread Jorge Vargas
On 8/28/06, tobiah <[EMAIL PROTECTED]> wrote: > def foo(thing): > > if thing: > return thing + 1 > else: > return -1 > > def foo(thing): > > if thing: > return thing + 1 > return -1 > > Obviously both do the same thing.

Re: Coding style

2006-07-25 Thread Gerhard Fiedler
On 2006-07-25 17:59:22, Antoon Pardon wrote: >> My view is: I ask for help on a public forum. I get what I get... and if >> I consider that someone who responded with something that's not >> immediately helpful has a potential to help me better, I try to get in >> a dialog and address what has bee

Re: Coding style

2006-07-25 Thread Antoon Pardon
On 2006-07-23, Gerhard Fiedler <[EMAIL PROTECTED]> wrote: > On 2006-07-23 06:24:09, Antoon Pardon wrote: > >>> In general, I'd say that in this case the example was not well-chosen. >>> After such a "shudder removal", a poster should IMO review what caused >>> the shudder, and rephrase the original

Re: Coding style

2006-07-23 Thread Gerhard Fiedler
On 2006-07-23 06:24:09, Antoon Pardon wrote: >> In general, I'd say that in this case the example was not well-chosen. >> After such a "shudder removal", a poster should IMO review what caused >> the shudder, and rephrase the original problem without the shudder. > > The shudder is not with the p

Re: Coding style

2006-07-23 Thread Antoon Pardon
On 2006-07-21, Gerhard Fiedler <[EMAIL PROTECTED]> wrote: > On 2006-07-21 09:00:43, Antoon Pardon wrote: > >> So we have code with certain shudder characteristics. And instead >> of trying to help the OP with his problem, some people react >> to the shudder and come with all sort of comments that m

Re: Coding style

2006-07-23 Thread Antoon Pardon
On 2006-07-21, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On 21 Jul 2006 12:00:43 GMT, Antoon Pardon <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > >> So we have code with certain shudder characteristics. And instead >> of trying to help the OP with his problem, some peopl

Re: Coding style

2006-07-21 Thread Bruno Desthuilliers
Lawrence D'Oliveiro a écrit : > In message <[EMAIL PROTECTED]>, Georg Brandl wrote: > > (snip) >>Other than in PHP, Python has clear rules when an object of a builtin type >>is considered false (i.e. when it's empty). So why not take advantage of >>this? > > Because the clearest rule of all is

Re: Coding style

2006-07-21 Thread Gerhard Fiedler
On 2006-07-21 09:00:43, Antoon Pardon wrote: > So we have code with certain shudder characteristics. And instead > of trying to help the OP with his problem, some people react > to the shudder and come with all sort of comments that might be > true if the code as shown was production code, but whi

Re: Coding style

2006-07-21 Thread Antoon Pardon
On 2006-07-20, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On 20 Jul 2006 08:50:44 GMT, Antoon Pardon <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > >> >> Suppose I have the following kind of code: >> >> while True: >> try: >> if len(result) > 0: >> foo() >>

Re: Coding style

2006-07-20 Thread Donn Cave
In article <[EMAIL PROTECTED]>, Antoon Pardon <[EMAIL PROTECTED]> wrote: > On 2006-07-19, Donn Cave <[EMAIL PROTECTED]> wrote: ... > > http://groups.google.com/group/comp.lang.python/msg/2de5e1c8384c0360 > > > > It's lengthy but very readable, and for me it has that quality of > > exposition where

Re: Coding style

2006-07-20 Thread Bruno Desthuilliers
Lawrence D'Oliveiro wrote: > In message <[EMAIL PROTECTED]>, Bruno Desthuilliers > wrote: > > >>Lawrence D'Oliveiro wrote: >> >>>In message <[EMAIL PROTECTED]>, Bob Greschke >>>wrote: >>> >>> >>> I'd go even one step further. Turn it into English (or your favorite non-computer language):

Re: Coding style

2006-07-20 Thread Antoon Pardon
On 2006-07-19, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On 19 Jul 2006 12:27:39 GMT, Antoon Pardon <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > >> >> I once had a producer consumer code. When the client asked whether new >> items were available the function could re

Re: Coding style

2006-07-20 Thread Antoon Pardon
On 2006-07-19, Donn Cave <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Georg Brandl <[EMAIL PROTECTED]> wrote: >> Lawrence D'Oliveiro wrote: > >> > One of my rules is, always program like the language actually has a Boolean >> > type, even if it doesn't. That means, never assume t

Re: Coding style

2006-07-20 Thread Antoon Pardon
On 2006-07-19, Georg Brandl <[EMAIL PROTECTED]> wrote: > Antoon Pardon wrote: > >>> Other than in PHP, Python has clear rules when an object of a builtin type >>> is considered false (i.e. when it's empty). So why not take advantage of >>> this? >> >> Because it doesn't always do what I want. >>

Re: Coding style

2006-07-19 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Georg Brandl wrote: > Lawrence D'Oliveiro wrote: >> In message <[EMAIL PROTECTED]>, Bob Greschke >> wrote: >> >>> I'd go even one step further. Turn it into English (or your favorite >>> non-computer language): >>> >>> 1. While list, pop. >>> >>> 2. While the le

Re: Coding style

2006-07-19 Thread Patrick Maupin
Terry Reedy wrote: > > > Carl Banks wrote: > >> def process_values(lst): > >> if not lst: > >> return > >> do_expensive_initialization_step() > >> for item in lst: > >> do_something_with(item) > >> do_expensive_finalization_step() > > Give

Re: Coding style

2006-07-19 Thread Donn Cave
In article <[EMAIL PROTECTED]>, Georg Brandl <[EMAIL PROTECTED]> wrote: > Lawrence D'Oliveiro wrote: > > One of my rules is, always program like the language actually has a Boolean > > type, even if it doesn't. That means, never assume that arbitrary values > > can be interpreted as true or false

Re: Coding style

2006-07-19 Thread Carl Banks
Patrick Maupin wrote: > The original post did not say "this function is iterating twice over > the same data." It only said that there might be a significant > computational cost on an empty iterator, and wished that the code would > somehow throw an exception to alert the programmer to this cost

Re: Coding style

2006-07-19 Thread Georg Brandl
Antoon Pardon wrote: >> Other than in PHP, Python has clear rules when an object of a builtin type >> is considered false (i.e. when it's empty). So why not take advantage of >> this? > > Because it doesn't always do what I want. > > I once had a producer consumer code. When the client asked whe

Re: Coding style

2006-07-19 Thread Patrick Maupin
Christophe wrote: > > The perverse wish, expressed in the specific example, that SOME piece > > of code SOMEWHERE should PLEASE throw an exception because some idiot > > passed a generator expression rather than a list into a function, is > > not apt to be well received by an audience which strive

Re: Coding style

2006-07-19 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Boris Borcic wrote: >> And I don't find `list(False)` to return an empty list be very obvious. > > What would be your choice ? ``list()`` or ``[]`` for empty lists and a `TypeError` for ``list(False)``. Just like it is right now. Ciao, Marc 'BlackJack' Rintsch --

Re: Coding style

2006-07-19 Thread Antoon Pardon
On 2006-07-19, Georg Brandl <[EMAIL PROTECTED]> wrote: > Lawrence D'Oliveiro wrote: >> In message <[EMAIL PROTECTED]>, Bob Greschke wrote: >> >>> I'd go even one step further. Turn it into English (or your favorite >>> non-computer language): >>> >>> 1. While list, pop. >>> >>> 2. While the len

Re: Coding style

2006-07-19 Thread Boris Borcic
Marc 'BlackJack' Rintsch wrote: > In <[EMAIL PROTECTED]>, Boris Borcic wrote: > >> Bruno Desthuilliers wrote: >>> empty_list = [] >>> bool(empty_list) is False >>> => True >> it's just a pity that the symmetric expression >> >> list(False) is [] >> >> doesn't hold. > > You want the empty list to

Re: Coding style

2006-07-19 Thread Ant
Christophe wrote: > ... you haven't beed using enouth generator expressions ... You should get yourself to the doctors about that cold dude. :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Coding style

2006-07-19 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Boris Borcic wrote: > Bruno Desthuilliers wrote: >> >> empty_list = [] >> bool(empty_list) is False >> => True > > it's just a pity that the symmetric expression > > list(False) is [] > > doesn't hold. You want the empty list to be a singleton!? And I don't find `list

Re: Coding style

2006-07-19 Thread Christophe
Patrick Maupin a écrit : > The perverse wish, expressed in the specific example, that SOME piece > of code SOMEWHERE should PLEASE throw an exception because some idiot > passed a generator expression rather than a list into a function, is > not apt to be well received by an audience which strives

Re: Coding style

2006-07-19 Thread Boris Borcic
Bruno Desthuilliers wrote: > > empty_list = [] > bool(empty_list) is False > => True it's just a pity that the symmetric expression list(False) is [] doesn't hold. I guess the problem is that if list(False) was thus defined, it would be difficult not to define list(True). And then the zen of

Re: Coding style

2006-07-19 Thread Boris Borcic
PTY wrote: > Which is better? > > lst = [1,2,3,4,5] > > while lst: > lst.pop() > > OR > > while len(lst) > 0: > lst.pop() > allways that either-or stuff ! And why did you not consider while len(lst) : list.pop() a neat middle ground, wouldn't you say ? Cheers, BB -- 666 ?? - 666 ~ .666

Re: Coding style

2006-07-19 Thread Georg Brandl
Lawrence D'Oliveiro wrote: > In message <[EMAIL PROTECTED]>, Bob Greschke wrote: > >> I'd go even one step further. Turn it into English (or your favorite >> non-computer language): >> >> 1. While list, pop. >> >> 2. While the length of the list is greater than 0, pop. >> >> Which one makes mo

Re: Coding style

2006-07-19 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Bruno Desthuilliers wrote: > Lawrence D'Oliveiro wrote: >> In message <[EMAIL PROTECTED]>, Bob Greschke >> wrote: >> >> >>>I'd go even one step further. Turn it into English (or your favorite >>>non-computer language): >>> >>>1. While list, pop. >>> >>>2. While t

Re: Coding style

2006-07-18 Thread Carl Banks
Jorge Godoy wrote: > "Carl Banks" <[EMAIL PROTECTED]> writes: > > > Well, I certainly can agree with that, except for the last point. :) I > > certainly wouldn't want to keep that unfortunate behavior around just I > > have something to use as an argument using len to test emptiness. > > On the o

Re: Coding style

2006-07-18 Thread Terry Reedy
"Patrick Maupin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Carl Banks wrote: >> def process_values(lst): >> if not lst: >> return >> do_expensive_initialization_step() >> for item in lst: >> do_something_with(item) >>

Re: Coding style

2006-07-18 Thread Jorge Godoy
"Carl Banks" <[EMAIL PROTECTED]> writes: > Well, I certainly can agree with that, except for the last point. :) I > certainly wouldn't want to keep that unfortunate behavior around just I > have something to use as an argument using len to test emptiness. On the other hand, having this behavior

Re: Coding style

2006-07-18 Thread Carl Banks
Bruno Desthuilliers wrote: > Carl Banks a écrit : > > Bruno Desthuilliers wrote: > > > >>There are less risk of a typo with "if a:" than with "if len(a) > 0". > > > > > > So, it's more important to protect against typos than subtle bugs? > > > > People making smart points are really annoying... !-

Re: Coding style

2006-07-18 Thread Bruno Desthuilliers
Carl Banks a écrit : > Bruno Desthuilliers wrote: > >>There are less risk of a typo with "if a:" than with "if len(a) > 0". > > > So, it's more important to protect against typos than subtle bugs? > People making smart points are really annoying... !-) wrt/ to the "subtle bug" point, MHO is t

Re: Coding style

2006-07-18 Thread Carl Banks
Bruno Desthuilliers wrote: > There are less risk of a typo with "if a:" than with "if len(a) > 0". So, it's more important to protect against typos than subtle bugs? Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Coding style

2006-07-18 Thread Carl Banks
Bruno Desthuilliers wrote: > "Irrelevant" may not be the best expression of my thought here - it's > just that Carl's assertion is kind of a tautology and doesn't add > anything to the discussion. If Python had been designed as statically > typed (with declarative typing), the rules would be differ

Re: Coding style

2006-07-18 Thread Bruno Desthuilliers
Volker Grabsch a écrit : > Bruno Desthuilliers <[EMAIL PROTECTED]> schrieb: > >>Carl Banks wrote: >> >>>Bruno Desthuilliers wrote: >>> >>>I'm well aware of Python's semantics, and it's irrelvant to my >>>argument. > > [...] > >>>If the language >>>were designed differently, then the rules would

  1   2   >