-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[.NET] Added .NET 8, NRT and more #253
Conversation
Important: |
this.<%= capitalize(property_name) %> = <%= property_name %> == null ? null : new <%= type_for(class_name(key), property_name, property) %>(<%= property_name %>); | ||
<%- end -%> | ||
<%- if !isValueType && required -%> | ||
<%= capitalize(property_name) %> = <%= property_name %> ?? throw new ArgumentNullException("<%= capitalize(property_name) %>", "<%= class_name(key) %>.<%= capitalize(property_name) %> cannot be null"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The template was generating "record-like" classes with getters only; in a sense providing an 'immutable' data structure. This PR is adopting the use of records directly, making a stronger statement about immutability.
During the constructor, we previously copyied the contents of enumerable items by calling 'new List(argument) for those properties that were enumerable. This disconnected the Message instance from its source (if one list or the other got changed, the other would not).
This proposed template simply assigns the input argument to the generated property.
@gasparnagy How careful do we need to be about immutability and/or effects of change here?
We could use an ImmutableList here to be explicit about intent and strengthen the behavior, go back to previous behavior of simply copying the list content, or accept this behavior of accepting the List argument as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ImmutableArray is desirable here, but i will require 1 extra dependency for .NET Standard tfm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think regardless of what structure we use to store the "immutable" list, we should go back to the previous model of "copying" the items from the input structure, so the simple assignment is not enough.
As this is package is not really used yet, maybe we should be more future proof and go for the ImmutableList accepting the fact that this way we have to add a dependency to System.Collections.Immutable
for the .NET Standard 2.0 target (in .NET 8 it is anyway included). So I would say, let's give it a try. If we see problems with this dependendency, we can still roll back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR is updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx. As far as I see now it takes ImmutableArray
as an input, so it will be the responsibility of the caller to ensure the immutability. I think this is good, but I wonder if we should generate an additional convenience overloads for the ctors that just take an IEnumerable<T>
and build the ImmutableArray
from it.
@clrudolphi Would creating an ImmutableArray
for calling the ctors cause any issues for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the constructor signature to accept the IEnumerable as a parameter, and have it create the ImutableArray property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree that we need to make a copy inside of constructor without any visible reason.
Maybe you have some code examples why it makes a problem and I can propose a some solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's clarify what we mean. Likewise, I do not think it necessary to create copies of the items within the source collections.
The design principle under consideration here is to provide a construction signature that is easy to use. The MS API Design Guidelines suggest that collection parameters be typed as interfaces and of a commonly used type, such as IEnumerable or IReadOnlyCollection.
As a convenience to users of the constructor, we can build an instance of an ImmutableArray from that provided IEnumberable argument and assign that to the property. Doing so doesn't copy the members of the collection (presuming T is a class, not a value type).
Since ImmutableArray is also IEnumerable, within the Messages library we can pass instances of ImmutableArray to constructors of other types (that accept IEnumberable) without needing an overloaded constructor.
If there is a concern about performance or memory overhead of creating a new instance of ImmutableArray out of an input IEnumberable, why not have the constructor test the run-time type of the argument, and if it is already an ImmutableArray, then simply assign it to the property; otherwise new up a new instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, then lets continue to use List copy as we have now
Yeah. But Gaspar and I had previous conversations about this library and at the time had agreed to limit ourselves to .net 6 as the baseline. Let's let him weigh in tomorrow.
Chris
________________________________
From: Romfos ***@***.***>
Sent: Sunday, September 15, 2024 1:47:02 PM
To: cucumber/messages ***@***.***>
Cc: Chris Rudolphi ***@***.***>; Review requested ***@***.***>
Subject: Re: [cucumber/messages] [.NET] Added .NET 8, NRT and more (PR #253)
@Romfos commented on this pull request.
________________________________
In .github/workflows/release-nuget.yaml<#253 (comment)>:
- name: Setup .NET
uses: ***@***.***
with:
- dotnet-version: 6.0.x
+ dotnet-version: 8.0.x
this line change only sdk version for release github action.
.NET standard 2.0 is still in tfm list
—
Reply to this email directly, view it on GitHub<#253 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAM7YMXVCF5N7MUY3WVLWZDZWXI2NAVCNFSM6AAAAABOHW4T6OVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGMBVGU2TGMRZGY>.
You are receiving this because your review was requested.Message ID: ***@***.***>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the overall goal and the concept of the PR is fine.
See my comment on the explicit listing of the .NET 8 target and also we should clean up the "immutable list" problem mentioned by @clrudolphi (see discussion there).
this.<%= capitalize(property_name) %> = <%= property_name %> == null ? null : new <%= type_for(class_name(key), property_name, property) %>(<%= property_name %>); | ||
<%- end -%> | ||
<%- if !isValueType && required -%> | ||
<%= capitalize(property_name) %> = <%= property_name %> ?? throw new ArgumentNullException("<%= capitalize(property_name) %>", "<%= class_name(key) %>.<%= capitalize(property_name) %> cannot be null"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the constructor signature to accept the IEnumerable as a parameter, and have it create the ImutableArray property.
@Romfos did you close this by accident? |
no, accroding to comment #253 (comment) implementation will stay the same |
Thanks for explaining! |
@Romfos Oh, I had missed that this had gotten closed. Even if we leave the collection class type unchanged, I would like to see the other changes proposed within this PR adopted. |
🤔 What's changed?
Template generator changes:
⚡️ What's your motivation?
This PR is result of discussion here cucumber/gherkin#281
🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
📋 Checklist:
This text was originally generated from a template, then edited by hand. You can modify the template here.