React: What WPF Should Have Been
wizardsofsmart.wordpress.com
wizardsofsmart.wordpress.com
It's seems like the XAML they went with is actually the better option -- it's close enough to other markup languages that any developer can pick it up with minimal effort, but not exactly the same so they can make any changes they want without hurting anyone else's compatibility or the larger ecosystem.
And (totally subjectively) XAML is actually nicer for developers and users than HTML+CSS+JS in some areas, if your willing to invest just a tiny amount of time to learn it.
--
Plus, Microsoft's UWP also lets you use a web browser too, if you prefer. If you feel your markup is better in HTML+CSS+SVG, Microsoft already supports that as well - https://docs.microsoft.com/en-us/windows/uwp/get-started/cre...
Well, that didn't happen with TypeScript. I think the perception of Microsoft has changed a lot since Nadella took over because they have really worked really hard to avoid the IBM trap.
On one hand you have developers and power-users who use Windows and care about privacy. And a probably much tinier number who don't use Windows but care enough about other people's privacy.
On the other hand you have all the web/JS/FOSS tech folk on Linux and macOS - these OSes have pretty tiny usage stats over all but I'd guess relatively high within that community - who don't care so much about Windows and as such just see the positive results of their FOSS efforts.
I wonder who's winning...
I know flexbox and stuff exist now, but I think it would have been a mistake to adopt HTML with its document-centric model to represent Windows applications.
Conceptually there are still no ways at the moment to reproduce full set of canonic layout managers from AWT: https://docs.oracle.com/javase/tutorial/uiswing/layout/visua...
Partial attempts to introduce flexibility in CSS were made only recently - flexbox and grid specifications.
But even those attempts look quite random and far from being well thought. For example concept of flex (portion of free space) in flexbox is defined by property flex, but in CSS Grid module the same concept is defined by 'fr' free space units. Yet the same entity in HTML was initially known as * (asterisk) units (<frame> and <table> metrics). (All these are expressed by * units in Sciter in their initial meaning).
I suspect that such no-one-is-responsible-for-overall-architecture in CSS was one of major motivations in XAML/WPF appearance.
XAML is WPF in easy mode.
In WPF you can get direct access to their retained mode graphics system, built on top of direct x, and ignore XAML completely.
Before making a claim like "React is what WPF should have been", the author should have done a lot more research into what WPF is and what could be done with it. The beauty of WPF isn't in XAML, it is in WPF's underlying framework and rendering engine. XAML is WPF's training wheels.
It's such a shame WPF is in maintenance mode instead of active development. I'd imagine a big reason for that is that it didn't gain the level of popularity Microsoft hoped it would. I don't think they did a good job of explaining and evangelizing it since release. UWP/Win2d seems to be what was meant to replace it, but it doesn't offer the same level of control and compatibility at all. I'm sure there's some grand long term plan I'm not privy to, but I'd be much happier in the short term if we could stop pushing windows store apps and get back to building frameworks for the hardcore.
Did you know there was a managed version of DirectX 9? Have you looked into C++/CLI? I'd love to understand the story of why the .net initiative changed direction in the last decade. I'd love to hear the master plan.
The political wars between WinDev (Windows and C/C++) and DevTools (Visual Studio and .NET) divisions.
With the mismanagemnt that happened with Longhorn, the WinDev gained in strenght Vista and Windows 7 happened, pushing aside all .NET related plans into DevTools alone.
Then with the failure of the initial store model, the DevTools kind of won in strenght got some of the ex-Midori devs, MDIL compiler became .NET Native and at the last couple of BUILDs you very barely see any talk about using C++ for UWP, rather portability across Linux/mobile OSes and ANSI C++ compatibility, everything else is shown in C#.
You can build whatever you want on top of the WPF foundation. That's how .net framework API's work.
WPF is a rendering engine, with a control management system build on top of it. XAML is an HTML like way of defining controls, but you don't have to use it. XAML is sugar, and I generally avoid it unless my application is super simple. You don't have to use their control management system either, you can go strait for the retained mode graphics system.
As much as Microsoft tries to make windows development look like web development through sugar on top (XAML is the most recent) to attract the new generation of web only developers, it's not. There's a lot of depth, performance, and control to be had there.
If you want to see what I'm talking about, get visual studio community edition (if you don't have visual studio already) and spend a weekend with WPF without XAML. I think you'll be surprised with how much fun you can have, and the level of control you can take. Make your own controls, override measure, arrange, and render.
And what's the difference between this and "unidirectional data flow"?
<TextBlock Text="{x:Bind PageTitle, Mode=OneWay}"/>WPF and its sister frameworks, Silverlight and UWP all promote this disconnected way to develop the UI. Create a XAML file that then needs to be carefully crafted in a way that hooks up to the code class files. It was initially sold as an idea that designers would build the XAML and the engineers would work on the code. They even released a mini-adobe lite suite marketed to designers.
UWP in its latest iteration seems to acknowledge XAML's shortcomings. They introduced a new new UI foundational framework call the VisualLayer (aka DirectComposition). It reminds me a lot of iOS's CoreAnimation framework.
We're bashing VB6 for this exact reason, and now this is cool again?
Just inlining views into JS wouldn't have been good. But when you add unidirectional data flow, composable components and lots of best practice docs, then you have a system that works really well.
They strictly kept any sort of code or logic out of XAML, annoyingly so to the point where you are writing converter classes to negate an expression. Compare that with the mishmash that is React.
For what it's worth, WPF does provide sufficient flexibility that it's possible to add support for expression-driven converters using markup extensions and an MSBuild task for compile-time codegen. Have a look at this:
https://github.com/Microsoft/PTVS/blob/ebfc4ca8bab234d453f15...
It can also be used completely inline, i.e.:
<TextBlock Text="{Binding Name, Converter={ext:Lambda 'x => x.ToUpper()'}"/>
This is the codegen step that extracts those lambdas from XAML and processes them:https://github.com/Microsoft/PTVS/blob/6bf34d3611d34e94eddb6...
and this is the helper classes that are used in its output:
https://github.com/Microsoft/PTVS/tree/6bf34d3611d34e94eddb6...
Note that it's language-agnostic; or rather, it uses the same language for expressions that the project itself does (so long as that language has a CodeDOM provider).
Of course, if anyone wants to take this code and go for it, you're quite welcome. Note that it has been also licensed more permissively under MIT as part of RTVS - probably a better starting point for that:
https://github.com/Microsoft/RTVS/tree/master/src/Common/Wpf...
https://github.com/Microsoft/RTVS/blob/master/src/Common/Bui...
IF WPF was still the primary UI tech on Windows I probably could get behind implementing such a library.
Main differences is that XAML processing is implemented in C# in .NET, and in C++/CX on UWP.
XAML on UWP supports static binding at compile time, and on WPF it is only dynamic (x:Bind vs Binding).
Finally the actual classes backing the UI components aren't 100% compatible, but do have most of the same methods and properties.
Anyone that knows WPF, shouldn't have any issue with XAML/UWP.
Most stock UWP components (the ones that come with the OS) are implemented in pure C++ using WRL (https://docs.microsoft.com/en-us/cpp/windows/windows-runtime...). This is mainly because they were already being actively implemented long before C++/CX became usable.
Anyone that knows their way around WPF, can make use of XAML, MVVM and all related UI concepts, regardless of the API differences between WPF, Silverlight, UWP and Xamarin.Forms.
For me they are all the same.
Why to imagine? Sciter ( https://sciter.com ) is exactly that - embeddable HTML/CSS engine for UI of desktop applications. And it was built at the same time: https://sciter.com/sciter/sciter-vs-wpf/
Its code already works on around 320 mln PCs and Macs "under the hood" so far... Quite comparable with spread of WPF applications, no?
As of Sciter itself ... It does have file I/O to load/read resources and data persistence from script but these are just auxiliary components to its main function (UI).
React, in the other hand, is dead simple and lightweight.
I wrote ASP.NET controls for a long time, and I see a lot of similarities in how I structure react components and how I would have written WebControls in ASP.NET.
I think in hindsight, my conclusion/realization from reading this article is that the lost opportunity for Microsoft was to re-invent the whole presentation layer with things like WPF and Silverlight, instead of trying to make it actually fit within the technology stack that people had settled on (HTML/CSS/JS).