Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting.Dictionary weirdo

Status
Not open for further replies.

vongrunt

Programmer
Mar 8, 2004
4,863
HR
Can anyone explain this to me:
Code:
Dim oDict: Set oDict = Server.createObject("Scripting.Dictionary")
Response.Write "Initial length: " & oDict.count & "<br>"
[b]Response.Write oDict.Item("blah")[/b]
Response.Write "Length after: " & oDict.count & "<br>"
Response.Write oDict.exists("blah") & " " & TypeName(oDict.Item("blah"))

Line in bold performs no assignments, key doesn't exist, no errors - but item with key "blah" and value Empty is created.

I'm also curious why Mircosoft treats trivial associative array (as seen in perl/php/javascript/whatever) as object... and restricts it's threading model to "Apartment".
 
Warning, take this with a grain of salt, it isbased on observation:
I think the MS created a core collection object that they re-used in multiple places. The "return an empty string" action also happens with the various Request collections and has actually become a common method of testing if a field exists in the Request collection.
As far as why Microsoft implemented associative arrays/collections the way it did, I have no clue. Especially with the obvious cross blending between the internal IIS objects (Request, etc) and external COM objects (Disctionary, etc).

My guess as to the 'how' of implementation is that they already had VBScript and the Windows Scripting objects, so when it came time to create objects for ASP they re-used as much of the existing components as possible. In reality objects like the Dictionary object have notthing to do with ASP and are not part of ASP, they are part of the Windows Scripting library that is expected to already exist on any machine running IIS. I have long had issues with them declaring the Dictionary object, FileSystem object, etc as parts of ASP because they are parts of the underlying OS, not ASP.

As far as Apartment threading, I don't know. It is possible it was simply laziness on the part ofthe developers. Apartment threading means that each thread has a copy of the global objects, so there is less concern about inter-thread communications and read/write locks. In fact, if you notice how each version of Windows gets bigger and requires even more RAM (on a much greater scale then, say, linux), there is a certain similarity between the OS's and the fact that ASP uses apartment threading. Basically it's easier to manage/develop, simpler to maintain, and just requires more horsepower, a common MS trend.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Salt taken, tnx for reply. :)

"Return an empty string" actions are OK for web stuff... what bugs me is that I didn't assigned anything to dictionary - I addressed non-existant key instead - and item count increased by one. By following that logic the following code would return 0/1:
Code:
Response.write request.Form.Count & "<br>"
Response.write request.Form("foo")
Response.write request.Form.Count & "<br>"
Regarding threading models, I remember some hi-scale Microsoft web products (Commerce Server in particular) used different version of Dictionary - with both threading models and hash-mapped keys (order of appending doesn't determine physical order of values).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top