I so agree.
Indeed. I believe we have case and point proof above. Oh well.
Dictionary manipulation in VB still does not compare to Python's. (Or Perl).
I agree. I would imagine this difference is due at least in part on the fact that VB6 was pretty much evolved from the original BASIC, at least in some form. That, as well as the fact that it is more a "give you a few tools, you work out the rest" type of mantra. Python and Perl were both designed much later, and for different purposes. (BASIC was, at it's inception, "all-purpose"... Although I'm not sure what that meant back then, clearly not very much) Perl was, as it's name implies, originally designed for creating "reports" both languages have clearly grown into something else, with VBScript being used in ASP pages and Perl and Python also finding themselves available for use online in Apache modules.
The only difference is that dictionary support is built right into Python and perl as part of the language itself. Visual Basic had to be backwards compatible (for business reasons I guess) with QBasic and even to a point BASICA and GW-BASIC, so it didn't really have the luxury of introducing new syntaxes for things like dictionaries and collections. Besides, it didn't even support being a provider of objects (it could consume objects I VB2, I think, but I don't think they were COM based). Visual Basic 4 integrated VBA into the mix, which meant VB4 applications could use collections.
The main problem with the collection is, as you passively pointed out using a carefully constructed python snippet, is that the collection object, for whatever reason, is immutable. Or more precisely, it's elements are. in order to "change" a value you would need to actually remove it and add it again.
This is why the collection is best used to store a collection of objects, the objects themselves can have their properties changes and so forth without a problem from the collection. I believe this particular limitation may be because of the way the collection is implemented internally.
However, the Dictionary Object is almost purely the same as a collection with most of the limitations removed. for example, you provide the following:
animals={}
animals["cat"]="meow"
animals["dog"]="woof"
animals["cow"]="moo"
animals
animals.values()
['woof', 'moo', 'meow']
animals.keys()
['dog', 'cow', 'cat']
animals["dog"]+="bark"
animals
You ask me to do something similar in VB. not too difficult.
[code]
Set Animals = CreateObject("Scripting.Dictionary")
Animals!cat = "Meow"
Animals!dog = "Woof"
Animals!cow = "Moo"
OutLn Join(Animals.Items(), ",")
OutLn Join(Animals.Keys(), ",")
Animals!dog = Animals!dog + "Bark"
OutDict Animals
Of course since the dictionary doesn't expose a way to get a string representation of itself it doesn't output those. And outln and out were both redefined by me to output to a textbox (as opposed to using Debug.Print).
As for a sorting routine, I would just use the class I wrote for that purpose. Besides, writing a sort routine isn't that hard, and one would only need to do it once. (bear in mind particularly the different problem domains of both python and VB6, VB6 comprises of "projects" and is used for creating applications. Python consists of an interpreter interpreting a single python file that may or may not reference other python files- it makes more sense in that case to try to put things such as sorting into built-in routines.
You have to be familiar with all 3 languages to make a fair comparison. What you are describing is a minor syntax issue
Funny, most of your problems with VB so far (aside from the sort one, I guess) have been "minor syntax issues". Besides, I even said as much in that paragraph:
It might be straightforward to somebody familiar with it
Finally, how about adding items from another dictionary to the the animals one?
For VB I would simply loop through all the keys and adding each key-value pair to the new array, just as I'm sure python is doing for you automagically behind the scenes. This isn't a problem in VB when you are familiar with it.
If you do a help(dict) at the python interpreter, you can use other dictionary methods that makes manipulation of dictionaries easy. Do you find that many in VB's version?
VB Classic? No. Of course not, it's based on COM which in and of itself is rather limited. and The person who developed the Scripting runtime did so in a single afternoon (Dead serious, I read that on Lieppert's blog I think) so they didn't think to add all this stuff. Besides, you can always write routines later.
speak of the devil. You swear by VB don't you?
Not counting this post I had an equal number of examples in C#. C# is now my main language, pretty much for the same reasons you go with python- more versatile... stuff. Generics alone would be enough for me to avoid returning to VB6 but combine that with LINQ and the gigantic class library and I may as well tear down the road back. But I still need to maintain my old VB6 applications.
I notice how you specifically pointed out VB6. VB.NET and C# have access to the framework and therefor have direct access to the many number of data structures available in the class library, such as List<T>,SortedList<T>,Dictionary<TKey,TValue>,Stack<T>,Queue<T> and a number of others. No Tree structures for some reason though.[/code]