[Gambas-devel] Collection bug (or strange behavior)

Benoit Minisini gambas at ...1...
Mon Mar 31 00:48:29 CEST 2008


On dimanche 30 mars 2008, Robert Rowe wrote:
> Try this:
>
> dim col as new collection
>
> col.add("somevalue","aaa")
> col.add("someothervalue","aaa") '<-- does not cause an error, it just
> overwrites "aaa"
> print col["aaa"] '<-- result is someothervalue because the second line
> overwrote the value without an error
>
> I would think that attempting to add an element whose key already exists
> should cause an error.
>
> Similarly, attempting to remove an entry that does not exits does not
> raise an error. I'd think that this could lead to some rather subtle
> bugs in a program that could be rather hard to detect.
>
> Robert Rowe
>

Collection works this way in Gambas, this is by design. This is not problem as 
soon as you know the way it works, and it behaves more like arrays.

You will find many places in Gambas where, instead of throwing an error, it 
uses a default behaviour that is usually the most common and useful. IMHO, of 
course. :-)

If you really think that a Collection that behaves like the VB Collection is 
useful, you can add it to the gb.vb component!

-- 
Benoit Minisini




More information about the Devel mailing list