Re: Coding style




<rurpy@xxxxxxxxx> wrote in message
news:1153168968.995422.198360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PTY wrote:
Which is better?

lst = [1,2,3,4,5]

while lst:
lst.pop()

OR

while len(lst) > 0:
lst.pop()

A dozen posts, but nobody has posted the right
answer yet, so I will :-)

It doesn't matter -- use whichever you prefer (*)
This is an angels on the head of a pin issue.

(*) -- If your code is part of an existing body of
code that uses one or the other style consistently,
then you should do the same.


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 more sense? Guess which one I like. CPU cycles be damned.
:)

Bob


.



Relevant Pages

  • Re: Beyond CL?
    ... > (defun dec-list (lst) ... > Heh, one of the features in my new language is complicated to implement ... Nobody can fix the economy. ...
    (comp.lang.lisp)
  • Re: Coding style
    ... while lst: ... but nobody has posted the right ... It looks like there are two crowds, terse and verbose. ...
    (comp.lang.python)
  • Re: Coding style
    ... PTY wrote: ... while lst: ... A dozen posts, but nobody has posted the right ...
    (comp.lang.python)
  • Re: Skolem paradoxical state of affairs
    ... and "COUNTABLE OUTSIDE M" are not necessarily equivalent! ... But still we have what I call a criterion problem, ... expressibility of 1st order language, ... And nothing LST states would be contradictory. ...
    (sci.logic)