Closed dzmitry-lahoda closed 5 months ago
Hi folks, I am interested to start with this. I am new to open source contribution, so would require some guidance to start off.
ReadOnly = False
dotnet test
Thanks @SubhajitS - let me know if you need any help.
Thanks also @dzmitry-lahoda . I'm thinking - is it worth just removing readonly
from Value altogether and not even having it in config?
@dzmitry-lahoda - is your main concern the defensive copies? The Value
field is get
only so there won't be any defensive copies.
One of my goals is to keep the Value Objects as immutable and as safe from default values as possible, so unless there's a compelling reason, I'd rather not introduce immutability.
@SubhajitS - I'm having second thoughts on this one. I've asked on runtime discord server, and there isn't any perf overhead. Would like to be proven wrong though...
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/struct#readonly-struct if i want readonly, i may mark stuct to be such. if I do not mark, I would have Value not readonly. i am thinking why to impose readonly on macro level? as it can be decided by consumer of macro (source generator). it will be more like rust approach. also recall ref/out/in modifiers in csharp. so making readonly is kind of opinionated I think.
@dzmitry-lahoda @SteveDunn The purpose of "value objects" is to be a in-place replacement for primative types.
Instead of using Int32
, Double
, Guid
, String
, etc, a non-primative type obsessed developer should use value objects. This is the whole purpose of Vogen - as far as I understand it.
Therefore, the value objects should behave as close as possible to the underlying primative type. Being immutable is the most important behavior IMO.
@SteveDunn A suggestion that came to my mind while reading this: maybe enhance the analyzers to promote the usage of readonly struct
instead of a struct
as an Information or Warning message?
I'm going to close this one as:
Thanks for the feedback. If it turns out that the performance overhead can be demonstrated, then we will of course revisit this.