You think that "it will increase productivity" as a given, but are you really sure about that? Structures work better than classes in special circumstances. I generalize for simplicity, but in the main scenario:
- They are unchanging.
- They are small, for example. usually no more than 3-4 fields.
- You generate tons (often millions or more) of them in a very short amount of time.
- You work with them in hard cycles.
- The code paths they move are optimized for these specific structures and do not perform boxing / unpacking operations.
There are others, but it's just out of my head. And even then we are talking about the often insignificant gain in productivity. As in microseconds minus.
Even if you can guarantee that your view models are immutable and tiny, other conditions are not preserved. Assuming one view model for each request, your web server will not process millions of requests per second. In addition, the MVC structure does not work with them in narrow loops and does not contain code paths optimized for this particular structure. As a result, the MVC framework will eventually perform many boxing / unpacking operations on your value types.
Bottom line - don't micro-optimize or rework your solution. Classes are great. And when optimizing, it always measures to make sure that you devote your time to a worthy enterprise. Do not worry about the little things when there is a big fish to fry.
Levi
source share