Why are System.Windows.Point & System.Windows.Vector mutable?

前端 未结 3 1581
鱼传尺愫
鱼传尺愫 2021-01-01 18:08

Given that mutable structs are generally regarded as evil (e.g., Why are mutable structs “evil”?), are there potential benefits that might have prompted the designers of the

3条回答
  •  情歌与酒
    2021-01-01 18:31

    Possibilities:

    1. It seemed like a good idea at the time to someone who didn't consider the use-cases where it would bite people. List.Enumerator is a mutable struct that was used because it seemed like a good idea at the time to take advantage of the micro-opts that would often happen. It's almost the poster-child for mutable structs being "evil" as it's bitten more than a few people. Still, it seemed like a good idea to someone at the time...
    2. They did think of the downsides, but had some use-case known to them where the performance differences went in struct's favour (they don't always) and was considered important.
    3. They didn't consider structs evil. "Evil" is an opinion about down-sides beating up-sides, not a demonstrable fact, and not everyone has to agree with something even if Eric Lippert and Jon Skeet say it. Personally I think they're not evil, they're just misunderstood; but then again, evil is often easier to deal with than misunderstood for a programmer, so that's actually worse... ;) Maybe those involved disagree.

提交回复
热议问题