Jump to content
Sign in to follow this  
Spiff59

Bug report: _ArrayPop

Recommended Posts

Spiff59

I helped someone with a bug last night.

The problem boiled down to basically the following:

#include<array.au3>
Dim $array[1] = ["xyzzy"]
_ArrayPop($array)
_ArrayAdd($array, "foobar")
Msgbox(1, "", $array[0])

One might think that that logically should work. Alas, no, it goes south in the _ArrayAdd statement.

The help file is ambiguous. It more imples, that when fed a one-element array, _ArrayPop will clear the last element ($array[0] = ""), when actually, it destroys the entire array ($array = "").

Here's my bug fix suggestion:

Delete _ArrayAdd, _ArrayCreate, _ArrayPop and _ArraySwap entirely from array.au3.

What's the point of a 10-20 line UDF function that replaces 1-2 lines of straightforward code?

I'd zap a half-dozen other functions out of the bloated array.au3 myself, were I god. I'd thought UDF's were for commonly-used, or complex, snippets of code, not bizarre routines imagined after dropping two tabs of orange sunshine.

It reminds me of the old DP joke: "Q:What is an elephant? A:A mouse designed to government specifications."

Thank you for your time. I feel better now.

Edited by Spiff59

Share this post


Link to post
Share on other sites
GaryFrost

Not a bug. Read the Remarks:

Remarks

If the array has one element left, it will be set to "" after _ArrayPop() is used on it.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
PsaltyDS

Not a bug. Read the Remarks:

The grammar is still ambiguous as to whether the element or the array is set to "". My English 101 prof would have red lined it.

I would recommend:

Remarks

If the array has one element left, the array will be deleted (set to "") after _ArrayPop() is used on it.

^_^

P.S. To address the OP: Changing the function is right out. Setting a value of "" is not "Clearing", as the "" value may be significant to the script. There would be no way to determine if the array had all elements popped, or if there was still one element ("") left to process.

If you bother to go through the change log in the help file (Appendix), you'll see _ArrayCreate() was already deprecated, and will be completely removed from a future version. And you are free to delete anything you like from your copy of Array.au3.

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Spiff59

P.S. To address the OP: Changing the function is right out. Setting a value of "" is not "Clearing", as the "" value may be significant to the script. There would be no way to determine if the array had all elements popped, or if there was still one element ("") left to process.

Yes, I understand that clearing the initial element is not a good solution either, although it would accomodate the example that I placed in my first post, which is an example that looks entirely reasonable. Neither is destroying the array a good solution for an "_ArrayPop" routine in my opinion. I'm sure the ability to maintain an array-type variable with zero elements would be opening up a can of worms.

So, I think if someone has enough understanding, or courage, to be calling _ArrayPop, they can certainly handle the mechanics of the first/last element themselves. I'd vote for sending about a third of Array.au3 to the circular file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×