comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » LIST "bug": .Remove on an empty list
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
LIST "bug": .Remove on an empty list [message #74002] Mon, 13 December 2010 11:53 Go to next message
Matt Haffner is currently offline  Matt Haffner
Messages: 34
Registered: October 2000
Member
Although this is easy to code around by checking the length before
calling .Remove, I was surprised this just didn't return silently:

IDL> l=list(1, length=100)
IDL> help,l
L LIST <ID=1424588 NELEMENTS=100>
IDL> l.remove,/all
IDL> help,l
L LIST <ID=1424588 NELEMENTS=0>
IDL> l.remove,/all
% PTR_FREE: Pointer type required in this context: P.
% Error occurred at: LIST::REMOVE
% LIST::REMOVE
% $MAIN$
% Execution halted at: $MAIN$

Passing it along to help the diagnosing of cryptic errors ;)

mh
Re: LIST "bug": .Remove on an empty list [message #74013 is a reply to message #74002] Fri, 17 December 2010 10:12 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
David Fanning wrote:
> Paulo Penteado writes:
>
>> And I find "if (~l) then ..." much more convenient than "if
>> (l.isempty()) then ...".
>
> IsEmpty has the value, of course, of letting you know what
> you were thinking months ago when you wrote the darn program. :-)

I agree.

if (l.isempty()) then

is self-documenting to the poor souls that follow who are tasked with maintaining/extending the code (and I include the
orig author in that group! :o).

But

if (~l) then

not so much. To quote Bob Martin from "Clean Code":

"The problem isn't the simplicity of the code but the /implicity/ of the code: the degree to which the context is not
explicit in the code itself"

I'm not advocating that code should be understandable to the point where your grandma can figure out what you're trying
to do (been there, done that, not good), but new hires with limited experience (i.e. not computer science/programmer
types) should be able to easily grok what's going on since they will pretty much not know that "lists currently already
overload their truth value". :o)

cheers,

paulv
Re: LIST "bug": .Remove on an empty list [message #74014 is a reply to message #74002] Fri, 17 December 2010 10:03 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Dec 17, 3:37 pm, David Fanning <n...@dfanning.com> wrote:
> Paulo Penteado writes:
>> And I find "if (~l) then ..." much more convenient than "if
>> (l.isempty()) then ...".
>
> IsEmpty has the value, of course, of letting you know what
> you were thinking months ago when you wrote the darn program. :-)

I would still say the same for the test of the object's truth value.
Other modern languages have used this for a while, and it is a common
convention that empty containers are false if empty, true otherwise.
Re: LIST "bug": .Remove on an empty list [message #74015 is a reply to message #74002] Fri, 17 December 2010 09:37 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paulo Penteado writes:

> And I find "if (~l) then ..." much more convenient than "if
> (l.isempty()) then ...".

IsEmpty has the value, of course, of letting you know what
you were thinking months ago when you wrote the darn program. :-)

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: LIST "bug": .Remove on an empty list [message #74051 is a reply to message #74002] Wed, 15 December 2010 09:22 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 12/15/10 9:15 AM, Adam Lefkoff wrote:
> On 12/14/2010 3:34 PM, Michael Galloy wrote:
>> On 12/14/10 9:39 AM, David Fanning wrote:
>>> P.S. Does anyone beside me and Dick Jackson see the
>>> danger in calling a new graphics system "new"? Coyote
>>> suggests the name Newest New Old Graphics System for
>>> the work I've been doing lately, but I don't know... :-(
>>
>> Yes, that's why I thought "function graphics" would be a good name.
>> Maybe some
>> kind of numbered system? I think we would be up to new 4.0 graphics
>> now? With
>> "old" graphics being direct graphics, then object graphics, Live
>> Tools, iTools,
>> and "new graphics"? Am I missing some other graphics systems?
>>
>> Mike
>
> I seem to recall that there was a precursor to Live Tools named
> "Insight" (circa 94/95). And if you're counting *all* the graphic
> systems, shouldn't "Watsyn" make the cut ??

Ah, Insight, yes. I'm just counting graphics systems in IDL, so I don't
think Watsyn counts.

Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: LIST "bug": .Remove on an empty list
Next Topic: spawning Fortran executables

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:28:49 PDT 2025

Total time taken to generate the page: 0.00697 seconds