Tag Archives: rust

WinUI Reactor: yet another way to code for the Windows desktop

Microsoft principal software developer engineer Alexandre Chohfi has posted about WinUI Reactor, an experimental framework for building WinUI applications using C# and a reactive pattern. The rationale for Reactor is two-fold:

  1. The popularity of React for web applications, and other reactive frameworks like SwiftUI and Jetpack Compose, makes using XAML for the user interface a barrier to adoption.
  2. Writing the user interface in plain C# is “easy for coding agents to read, write and check, so we now design for agents as well as people,” said Chohfi.

Note that Reactor is not a new platform, it is another way to code for WinUI, the existing platform which is supposedly the native UI framework for Windows but which competes with old-style Win32 (targeted by Windows Forms) and the DirectX-based WPF (Windows Presentation Foundation).

The easiest way to get started with Reactor is via the winapp CLI. Install the latest version and type winapp new selecting Reactor MVU App.

Creating a Reactor app with winapp.

The template coincidentally creates a counter app similar to the one in Chohfi’s post. The UI is coded in a Render method and there is no XAML file, everything is done in C#.

The Reactor demo app in Visual Studio Code.

Chohfi’s variant, which is also in the docs, is simplified but functionally the same. The template demo app calls UseReducer, whereas the documented demo calls UseState.

This may seem a terrible time to introduce a new (first previewed at Build in May) C# framework for desktop Windows. The niche for Windows desktop apps, mainly business applications, continues to shrink. Developers already face too many choices. Legacy .NET applications generally use Windows Forms or WPF, both of which still work.

It is hard to see many React developers wanting to switch to WinUI, when there are many ways to code desktop applications in JavaScript or TypeScript, including React Native, which seems a more natural choice.

Another issue is that this is not cross-platform. Coding a new application for Windows only seems short-sighted in most scenarios, hopeless for the consumer market, and for business use limited to companies standardised on Windows. That said, there is always an argument for using native frameworks on each platform, if the resources exist to build WinUI for Windows, SwiftUI for Mac and so on.

There is a Rust variant of Reactor and one can see this being of considerable interest, to Microsoft internally as well as for other developers. AI plus Rust is a potent combination.

There are indications that Microsoft is serious about Reactor, particularly in the remarks in Chohfi’s post about new Reactor controls being “candidates to land in WinUI itself,” and that “we’re actively working with the C# team” such that Reactor may influence the C# language.

I was also interested in Chohfi’s remarks about the mental model required to understand application code. For a XAML-based app, he said that “what does this screen look like when Count is 5 is a question you answer by reading three files and mentally running a binding engine. In Reactor, that last question has a very boring answer: read Render().”

I suspect that this is a reason for the continuing appeal of the Windows Forms framework. The mental model seems easy: one places controls on a canvas, sets their properties, and for interactivity one can just double-click a button and write the code that will run. This does not work so well for a complex application, but for something simple it is fine.

The MVVM (model-view-viewmodel) architecture which is common (though not required) for .NET applications has advantages, but even Microsoft architect John Gossman who was an early advocate for the pattern said that “for simple UI MVVM can be overkill” and that large numbers of bindings impact performance.

Reactor is MVU (model-view-update), as is React. In this pattern, the model is the state of the application, the view displays the state to the user, and update sends messages to update the state, triggered by user interaction or server activity.

A new era of AI-driven application rebuilds – now it is Microsoft Office and Adobe Photoshop

AI coding makes it easier and quicker to re-create existing applications with new code, side-stepping copyright concerns since copyright protects code rather than specification.

In February this year Cloudflare rebuilt Next.js with AI in one week and then followed with a WordPress-compatible CMS (content management system) called EmDash.

Brandon Thomas, a developer from Atlanta, Georgia in the USA, founded Artcraft with the goal of creating clean-room implementations of popular (and expensive) applications including Adobe Photoshop, LightRoom and InDesign; Figma; Microsoft Word, Excel and PowerPoint; AutoDesk’s AutoCAD, and more.

The applications are coded in Rust, run cross-platform on Windows, macOS, Linux and FreeBSD, and Web via WebAssembly, and are open source on GitHub under the Apache 2.0 license. The GUI is driven by the egui library, which means controls are not native but drawn by the library.

On LinkedIn, Thomas said that “we do not decompile binaries or copy Adobe Code” and “yes, I am actually an engineer.”

The ArtCraft implementations have some advantages over the commercial originals, in that they run on Linux, promise no tracking or ads or telemetry gathering, and can perform well thanks to the Rust’s efficiency.

On Hacker News Thomas said that “software is over” and that this initiative heralds a new era of escape from what he called “cellphone incrementalism and platform lock-in.”

Let us not get carried away yet. I tried WordCraft (whose name I recall from a word processor for the Commodore Pet which could only hold a few paragraphs in memory before painful paging to disk) and was both impressed and disappointed. It looks great but failed to render a complex Word document which I have used before to test LibreOffice.

WordCraft scrambled this awkward Word document

It is early days though and no doubt these and other issues will be fixed; most of the ArtCraft applications are described as Alpha releases.

Although the clean-room method is well established as a defence against copyright infringement, it does not remove patent restrictions. It is also now obvious that treating code as the essence of an application’s intellectual property is no longer possible and one must expect legal arguments if these applications, or other similar works, gain ground.

Nevertheless, the assumption that recreating applications to escape vendor lock-in is too expensive and difficult is now breaking down.; it is a big change for the industry even if, right now, it is hard to see all the implications.

Five facts about Rust

Rust is a programming language aimed at system programming – for which high performance and low-level system access is essential – but with safety features that make it harder to write dangerous or insecure code (though it is still possible). Since all programmers value both speed and stability, Rust is being used for tasks other than system programming as well. Rust is open source and sponsored by Mozilla, which uses Rust in its own development including parts of the Firefox web browser.

Rust is not one of the most-used programming languages; according to a StackOverflow survey only 3.2% of developers use it. Among professional developers that figure drops to 3.0%.

Yet Rust comfortably tops the list of most loved languages.

image

Second, Rust has built-in support for unit tests, in conjunction with Cargo, the Rust build system and package manager. Cargo will both generate test functions and run tests for you. You can do unit tests in any language, but this is a great way to prompt developers to use them.  Tests are a big deal. I recall Sqlite developer Dr D Richard Hipp telling me that testing was core to the project and without it, it could not progress as it does. Sqlite has 662 times more test code than the code in the Sqlite library itself.

Third, Rust can be compiled to WebAssembly so you can run it in a web browser.

Fourth, Microsoft is considering using Rust on the basis that it “could eliminate an entire class of vulnerabilities before they ever happened”.

Fifth, work is under way to build a new operating system with Rust, called Redox. I wrote about this briefly for the Register.

If asked to think of a language that is as efficient and powerful as C++ but nicer and for many of us more productive to use, I think of Delphi (or Object Pascal). Delphi has an ardent niche following but is unlikely to grow its usage much beyond it. Rust on the other hand is a modern language that benefits from things we have learned about programming in the last forty years (C++ was first thought by Bjarne Stroustrup when writing his PhD thesis, though the name dates from 1983), and with a refreshing lack of legacy. And Delphi is not open source, unless you mean Lazarus.

Worth a look if you have a moment – see here for how Verity Stop got on.