jrtom: (Default)
If I want to know if a given key is in a Dictionary, I'll do a Contains check myself.

In particular, I do not want you to throw an exception if I either

(a) attempt to retrieve a value for a key not in the dictionary, or
(b) attempt to set a value for a key in the dictionary.

Seriously. Not everything that might possibly be an error needs to result in throwing an exception (and had it occurred to you that I might want to _replace_ a value in the dictionary without the extra overhead of a call to Remove()?). Sheesh.

Your Somewhat Reluctant Disciple,

[livejournal.com profile] jrtom

PS: And get a decent collections API already, for [INSERT DEITY HERE]'s sake. Power Collections is a place to start, but by no means a place to finish...and it does not make up for many existing inadequacies.
jrtom: (Default)
[I don't know of anyone that reads this that will care. But maybe it will prove useful to someone.]

As I've just spent a while being bitten by this, I thought I'd pass this hard-won information along:

In C#, structs are passed by value, not reference (even though they act in many respects like classes).

An example, taken from all-too-real life, in which this becomes a problem:
Suppose that you have a dictionary in which you're keeping structs that contain statistics, stored in fields. Periodically, you retrieve a struct from this dictionary and update one of its statistics. However, since structs are passed by value, however, the struct that you modify is not the same as the one that the dictionary owns, and so the dictionary's struct's statistics are never modified.

That is to say: AAAAAAAARGH! (I mean, seriously: I realize that C# has a lot of adherents that came directly from C/C++, and those languages do the same thing. But why would you _want_ to pass a struct by value? All that stuff dumped on the stack...and structs can be _huge_.)

Profile

jrtom: (Default)
jrtom

May 2011

S M T W T F S
1234567
891011121314
1516 1718192021
22232425262728
29 3031    

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated 12 August 2025 21:16
Powered by Dreamwidth Studios