Explicitly typed variables #526
Replies: 1 comment 1 reply
|
I think this is a great discussion. To enable "TitleBar x = new()" we'd need to switch to record construction, rather than factory methods. this actually works today, with one exception, you have to register the handler for the reconciler. At the moment the Factory method call does the registration, so we get AOT trimmable type references and have no registration process. Both of these can be worked on... but, the point is, that if you want to play with this... for every type you want to use, call the factory method for it once -- or, just change the code in the project to force the registration of all the handlers (will break AOT trimming, but to play with, you are fine). now, you can use the elements:
The elements all have a suffix of "Element" to avoid collision with the WinUI types for every single thing... so, if you really like this model and we decide to switch, we'd want to figure out a better naming convention. I encourage you to try out different syntaxes and see what you think looks best. I'm not totally convinced on the factory+fluent, i think we should play around and see what works best with C#. |
Uh oh!
There was an error while loading. Please reload this page.
I've noticed every code example from Reactor uses implicitly typed variables. I know this varies from person to person, but personally, I think explicitly typed variables feel better in C#. So I was wondering what would be the best way to present them.
All examples look like
var appTitleBar = TitleBar(...things in title bar...);I haven't tried Reactor, so I assume you can do, right now, for example
TitleBar appTitleBar = TitleBar(...things in title bar...);but that looks kind of ugly and redundant. A while ago they fixed the redundancy and you can do
TitleBar appTitleBar = new( );but I'm not sure you can do that in Reactor and, honestly, it feels like it goes against the spirit of it - or should Reactor start using the
newkeyword?And doing
TitleBar appTitleBar = (...things in title bar...);also doesn't feel very right. Suggestions?
It feels a little silly to dwell on this, given that right after the = you see the type, but that's true of all C# code using var and that still feels strange to me.
And just so we're clear, I'm not advocating to eradicate the use of var here, just a good way of not using it.
All reactions