René's URL Explorer Experiment


Title: [C#] How to handle unconstrained optional generic type arguments · Issue #322 · plotly/Plotly.NET · GitHub

Open Graph Title: [C#] How to handle unconstrained optional generic type arguments · Issue #322 · plotly/Plotly.NET

X Title: [C#] How to handle unconstrained optional generic type arguments · Issue #322 · plotly/Plotly.NET

Description: This is a specific interop problem between the F# core API and the native C# layer. In short, I'd like to ask for feedback on which type of API surface looks better/more intuitive for C# users and why. I also added a in-depth problem des...

Open Graph Description: This is a specific interop problem between the F# core API and the native C# layer. In short, I'd like to ask for feedback on which type of API surface looks better/more intuitive for C# users and ...

X Description: This is a specific interop problem between the F# core API and the native C# layer. In short, I'd like to ask for feedback on which type of API surface looks better/more intuitive for C# users ...

Opengraph URL: https://github.com/plotly/Plotly.NET/issues/322

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[C#] How to handle unconstrained optional generic type arguments","articleBody":"This is a specific interop problem between the F# core API and the native C# layer.\r\n\r\nIn short, I'd like to ask for feedback on which type of API surface looks better/more intuitive for C# users and why. I also added a in-depth problem description for the curious further below.\r\n\r\n## Ask for feedback\r\n**Please react with 🚀 for Option 1, or 🎉 for Option 2. Detailed feedback via comments are highly appreciated**\r\n\r\nAs the C# API is shaping out, we encountered some specific friction points between F# and C# that need workarounds. This is not bad per se, but has an influence on the API surface.\r\n\r\nIn short, we need a `Optional\u003cT\u003e` type for unconstrained optional parameters that can be both value and reference types.\r\n\r\nWe now have two ways of using them:\r\n\r\n1. 🚀 use `Optional\u003cT\u003e` for ALL optional parameters. This would make the signature of `Chart.Column` look like this:\r\n\r\n![image](https://user-images.githubusercontent.com/21338071/178225304-7ca15114-2fa0-4e72-b052-d22dc158b9d6.png)\r\n\r\n2. 🎉 only use `Optional\u003cT\u003e` where needed. In our example, these are the optional arguments `Base`, `Width`, and `Text`. This makes the signature more concise, but makes it less obvious that there is no special ceremony of setting these values. This would make the signature of `Chart.Column` look like this:\r\n\r\n![image](https://user-images.githubusercontent.com/21338071/178229348-1a607ae0-9c0f-4fd8-85a9-49b83a487118.png)\r\n\r\n**Which of these signatures/API surfaces are more comprehensible for a C# user?** This will influence hundreds of functions, so it is an important decision for Plotly.NET's C# API.\r\n\r\nin both cases, you can call the function the same, so from a usage perspective these approaches are identical:\r\n\r\n```csharp\r\nChart.Column\u003cint, string, string\u003e(\r\n    values: new int[] { 3, 4 },\r\n    Keys: new string[] { \"first\", \"second\" },\r\n    Width: 1,\r\n    Base: 4\r\n)\r\n```\r\n\r\n## In-depth problem description\r\n\r\nPlotly.NET's core F# API makes heavy use of generic optional parameters. Here is an example:\r\n\r\n```fsharp\r\ntype Foo() =\r\n    static member Bar(\r\n        mandatory: string, \r\n        ?optNoProblemo1: int,\r\n        ?optNoProblemo2: DateTime,\r\n        ?optNoProblemo3: seq\u003c#IConvertible\u003e,\r\n        ?optProblem: #IConvertible // this one is problematic\r\n    ) =\r\n        ...\r\n```\r\n\r\nfor the respective C# Layer, we have to add type constraints on these optional parameters and make them nullable so we have a sure way of wrapping parameters that are set by the caller as `Option.Some(value)`, and parameters not set by the caller as `Option.None`. This is a little awkwardness coming from optional parameter interop between the two, but that's not the problem: \r\n\r\n```csharp\r\npublic static int Bar\u003cOptType\u003e(\r\n    string mandatory,\r\n    int? optNoProblemo1 = null,\r\n    DateTime? optNoProblemo2 = null,     \r\n    IEnumerable\u003cOptType\u003e? optNoProblemo3 = null,\r\n    OptType? optProblem = null\r\n)\r\nwhere OptType : IConvertible\r\n=\u003e\r\n    Plotly.NET.Chart2D.Chart.Foo(\r\n        mandatory: mandatory,\r\n        optNoProblemo1: optNoProblemo1,\r\n        optNoProblemo2: optNoProblemo2,\r\n        optNoProblemo3: optNoProblemo3,\r\n        optProblem: optProblem\r\n    );\r\n```\r\n\r\nThe problem is that `optProblem` cannot use `null` as default value, because it can be either reference or value type:\r\n\r\n![image](https://user-images.githubusercontent.com/21338071/178223729-315a2cc8-8e75-460d-8227-c256318dbb48.png)\r\n\r\nWe also cannot use `= default` instead of `= null`, because then we have no way of checking if the value was actually set as a default value (in that case we want to convert to `Some(value)`) or if it was not set (and should therefore be wrapped as `Option.None`).\r\n\r\nTo fix this, we use a class `Optional\u003cT\u003e`:\r\n\r\n```csharp\r\npublic readonly record struct Optional\u003cT\u003e(T Value, bool IsValid)\r\n    {\r\n        public static implicit operator Optional\u003cT\u003e(T Value) =\u003e new(Value, true);\r\n    }\r\n```\r\n\r\nwhich sets `IsValid` to true when a value is set, and false otherwise.\r\n","author":{"url":"https://github.com/kMutagene","@type":"Person","name":"kMutagene"},"datePublished":"2022-07-11T08:57:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/322/Plotly.NET/issues/322"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:95bba147-86e7-db71-75f7-15a12d8edf12
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDD58:A65AE:1D57ED:272B26:698F95B7
html-safe-nonceeead6150f14adbceeb338689ae5a7c257be6305f4c7ac66018bb99c66b472a92
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDU4OkE2NUFFOjFENTdFRDoyNzJCMjY6Njk4Rjk1QjciLCJ2aXNpdG9yX2lkIjoiMTYxOTEwMjM3MTk5MTc1NDE2NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacf6d259d19cd9a7d021bdb48a3602a2a8058a5831d333bc8734185606cfb0916c
hovercard-subject-tagissue:1300411423
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/plotly/Plotly.NET/322/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b852a1262a3435064a9055fcc06e0f69a2ee358c74e54fca8c02af75901472a7/plotly/Plotly.NET/issues/322
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b852a1262a3435064a9055fcc06e0f69a2ee358c74e54fca8c02af75901472a7/plotly/Plotly.NET/issues/322
og:image:altThis is a specific interop problem between the F# core API and the native C# layer. In short, I'd like to ask for feedback on which type of API surface looks better/more intuitive for C# users and ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamekMutagene
hostnamegithub.com
expected-hostnamegithub.com
None5f47eb8d0aaafbfcb6a8220a40bd81431acf688857c575e6489670c394cfa36f
turbo-cache-controlno-preview
go-importgithub.com/plotly/Plotly.NET git https://github.com/plotly/Plotly.NET.git
octolytics-dimension-user_id5997976
octolytics-dimension-user_loginplotly
octolytics-dimension-repository_id58708375
octolytics-dimension-repository_nwoplotly/Plotly.NET
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id58708375
octolytics-dimension-repository_network_root_nwoplotly/Plotly.NET
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release09a8136f6e8f8fd3078d54ce5f8b7adb493d44a7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/plotly/Plotly.NET/issues/322#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fplotly%2FPlotly.NET%2Fissues%2F322
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fplotly%2FPlotly.NET%2Fissues%2F322
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=plotly%2FPlotly.NET
Reloadhttps://github.com/plotly/Plotly.NET/issues/322
Reloadhttps://github.com/plotly/Plotly.NET/issues/322
Reloadhttps://github.com/plotly/Plotly.NET/issues/322
plotly https://github.com/plotly
Plotly.NEThttps://github.com/plotly/Plotly.NET
Notifications https://github.com/login?return_to=%2Fplotly%2FPlotly.NET
Fork 101 https://github.com/login?return_to=%2Fplotly%2FPlotly.NET
Star 834 https://github.com/login?return_to=%2Fplotly%2FPlotly.NET
Code https://github.com/plotly/Plotly.NET
Issues 43 https://github.com/plotly/Plotly.NET/issues
Pull requests 3 https://github.com/plotly/Plotly.NET/pulls
Discussions https://github.com/plotly/Plotly.NET/discussions
Actions https://github.com/plotly/Plotly.NET/actions
Projects 0 https://github.com/plotly/Plotly.NET/projects
Security 0 https://github.com/plotly/Plotly.NET/security
Insights https://github.com/plotly/Plotly.NET/pulse
Code https://github.com/plotly/Plotly.NET
Issues https://github.com/plotly/Plotly.NET/issues
Pull requests https://github.com/plotly/Plotly.NET/pulls
Discussions https://github.com/plotly/Plotly.NET/discussions
Actions https://github.com/plotly/Plotly.NET/actions
Projects https://github.com/plotly/Plotly.NET/projects
Security https://github.com/plotly/Plotly.NET/security
Insights https://github.com/plotly/Plotly.NET/pulse
New issuehttps://github.com/login?return_to=https://github.com/plotly/Plotly.NET/issues/322
New issuehttps://github.com/login?return_to=https://github.com/plotly/Plotly.NET/issues/322
[C#] How to handle unconstrained optional generic type argumentshttps://github.com/plotly/Plotly.NET/issues/322#top
Area: CSharphttps://github.com/plotly/Plotly.NET/issues?q=state%3Aopen%20label%3A%22Area%3A%20CSharp%22
help wantedhttps://github.com/plotly/Plotly.NET/issues?q=state%3Aopen%20label%3A%22help%20wanted%22
https://github.com/kMutagene
https://github.com/kMutagene
kMutagenehttps://github.com/kMutagene
on Jul 11, 2022https://github.com/plotly/Plotly.NET/issues/322#issue-1300411423
https://user-images.githubusercontent.com/21338071/178225304-7ca15114-2fa0-4e72-b052-d22dc158b9d6.png
https://user-images.githubusercontent.com/21338071/178229348-1a607ae0-9c0f-4fd8-85a9-49b83a487118.png
https://user-images.githubusercontent.com/21338071/178223729-315a2cc8-8e75-460d-8227-c256318dbb48.png
Area: CSharphttps://github.com/plotly/Plotly.NET/issues?q=state%3Aopen%20label%3A%22Area%3A%20CSharp%22
help wantedhttps://github.com/plotly/Plotly.NET/issues?q=state%3Aopen%20label%3A%22help%20wanted%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.