SteveDunn / Vogen

A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
Apache License 2.0
875 stars 45 forks source link

Discourage the default 'int' type for ValueObject #392

Closed hrumhurum closed 1 year ago

hrumhurum commented 1 year ago

Just a small feedback related to first impressions. First of all, the package is pretty useful and thank you for taking your time and efforts to create it.

However, it has a drawback related to the product perception: the default int type of ValueObject. I mean the very first example from the home page:

[ValueObject]
public partial struct CustomerId
{
}

It presents a serious perceptional problem because it is not clear what type the resulting CustomerId value will have. A much better approach is to always be explicit:

[ValueObject<int>]
public partial struct CustomerId
{
}

or

[ValueObject(typeof(int))]
public partial struct CustomerId
{
}

While I see where the default int idea came from, I want to stress that not everyone's experience revolves around integers. In database and ORM worlds maybe it is int, but for someone else it would string, or something completely different based on a particular problem domain.

I suggest to consider a possible obsolescence of [ValueObject] usage in favor of its explicit variants like [ValueObject(typeof(int))] that would make Vogen approachable to everyone, out of the box.

SteveDunn commented 1 year ago

Thanks for the feedback and praise of the project - it means a lot to hear such things!

I will be explicit with the type in the first examples and will also highlight that int is an arbitrary default and that user would probably want to change the default to suite their needs.

Maybe even have an option in the global configuration that basically fails the build if someone doesn't provide the type explicitly.

SteveDunn commented 1 year ago

Thanks again for the feedback. I've updated the readme and added this feature request.

https://github.com/SteveDunn/Vogen/issues/393