Question about idioms for clearing a list

Ed Singleton singletoned at gmail.com
Wed Feb 8 07:56:14 EST 2006


On 08/02/06, Magnus Lycka <lycka at carmen.se> wrote:
> Ed Singleton wrote:
> > I'm a fairly average programmer (better than average compared to my
> > immediate colleagues).  I've read every tutorial I can get my hands
> > on, but I have no _memory_  of ever coming across the del keyword, let
> > alone that it is fundamental to Python, and I have no idea what
> > collections school is.  I doubtless have read of it at some point, but
> > as no importance has ever been attached to it, I have probably not
> > remembered it.
> >
> > Similarly, I remember slices simply because they are handy, not
> > because I have ever heard of them being fundamental before.
>
> Ok, I can understand that, but I  think that you really understand
> that the strength of a programming language such as Python is that
> it's like lego bricks. You have some basic pieces, and you can
> combine them to into something unique that does what you want.
>
> There are plenty of statements, operators, functions, types, modules
> and other things in Python already. I can well imagine that you had
> forgotten about del, and that you don't immediately think about slices
> when you wonder how to empty a list. It's like when I build lego with
> my son. I guess he has around 2000 pieces, and it's not always easy
> to spot what you need. It was difficult enough when I was a kid. Now
> there are so many different kinds of pieces, shaped to fulfil some
> niche usecase.
>
> One thing that I'm sure of is this: Making more kinds of odd-shaped
> "pieces", especially prepared to solve the specific problem I'm facing
> right now, won't make it easier to understand or use Python in the
> long run.

I agree utterly with this, particularly the general philosophy of
having simple bricks that work in as many different places as
possible.

The point is that having to use del to clear a list appears to the
inexperienced as being an odd shaped brick when they've already used
the .clear() brick in other places.

Having bricks that work in lots of places makes the language
'guessable'.  "I've never cleared a list before, but I've cleared
dictionaries and I guess the same way would work here".

The problem is you have to be very careful when talking about this,
not to use the C-word, because that's the hobgoblin of little minds,
whereas in almost every other field it is considered an important part
of usability.

> I've used Python for almost 10 years now, and I still learn new
> things, and I sometimes come across things that I once new but
> had forgotten.
>
> It might work for a while to add a new convenience function as soon
> as someone finds that they don't immediately now how to solve a
> certain problem. It's my impression that that's pretty much the idea
> with PHP. It's not Python though. PHP is only successful in a fairly
> narrow (if important) niche, it has failed in getting used outside
> its niche, and I assume we'll see a decline in its use one the web
> pretty soon, just as it happened with Perl. (Whether RoR, something
> Python based or something entirely new will replace it is beyond my
> radar screen though.)
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list