575 points · by zengid · 8y ago · 283 comments
It doesn't serve the author well to make this comparison. Saying it's less messy to manage Proton/React source code files and the associated Node/JS/etc infrastructure is an extremely dubious claim. One of the things I like best about Qt is how non-messy Qt development is. Most everything (source files, resources, etc.) lives in a well-organized project that is easily managed using the Qt Creator IDE. The project structure is well-documented and standardized.
It's also quite strange to compare React code to code using the Python binding for Qt. That's not how most Qt apps are written. Most Qt apps these days use QML, which is based on regular old JavaScript. Besides being a more accurate representation of the way Qt development is normally done, it would also be more interesting to compare one JavaScript-based framework to another. (Although I recommend not making the comparison at all, since I don't believe a fair comparison would favor Proton.)
import QtQuick 2.9
import QtQuick.Controls 1.3
ApplicationWindow {
title: "Example"
visible: true
width: 300
height: 300
Button {
text: "Button"
anchors.centerIn: parent
onClicked: console.log('Hello')
}
}I may be biased, but to me the QML code is much cleaner and clearer than JSX.
You have been able to bind closures to events in Qt for... dunnno... 6 years maybe ?
View = fn(state) solves longstanding issues with all the previous approaches, and of course it decreases their complexity. It is also the first approach that's breaching the platform barrier successfully while maintaining the high-level. You can write React for countless of targets, being able to re-use and apply the eco-system.
Could you please paste an example of a real, functional QT component? For instance a component that is re-used in another component,
const A = ({ text }) => <div>{text}</div>
const B = () => <A text="hello" />
<B /> // -> <div>hello</div>
as well as functional composition (higher-order-components): const canBeDisabled = Component => props => props.disabled ? null : <Component {...props} />
const ComposedB = canBeDisabled(B)
<ComposedB /> // -> <div>hello</div>
<ComposedB disabled /> // -> null
an example for statefull components would also be nice: class C extends Component {
state = { count: 0 }
up = () => this.setState(state => ({ count: state.count + 1 })
render() {
return <div onClick={this.up}>{this.state.count}</div>
}
}
<C /> // -> <div>0</div>, clicks count up reactivelyHave they got the data grid API's working yet?
The data grid has still problems on macOS unfortunately, but @andlabs is working on it...
Seems to me that this should use far fewer resources (especially memory) and make it easier to make an App look more 'MacOS'y. Very eager to give it a go!
https://i.imgur.com/g94LOvE.png
It uses around 35MB.
For the comparison, IDE sketch (editor with syntax highlighting) from Sciter (HTML/CSS/script engine) SDK (https://github.com/c-smile/sciter-sdk/tree/master/samples/id...) takes 43 MB.
Screenshot: https://sciter.com/wp-content/uploads/2018/05/idea-ide.png
Resource measurements: The sample "Notepad" app (just a text box in a window, no copy/paste, etc.) uses 79 MB. For comparison the same app built using Xcode uses 27 MB, and TextEdit uses 40 MB.
Not that I'd be concerned about a few tens of MB nowadays but on the whole we're consuming computing resources at the same rate faster hardware is put out (Gates' law).
I have a Pentium 3 running NT4 sitting on the same desk and it is faster at many tasks than my i5 workstation. Visual Studio 6 especially is super snappy. How then can Slack, on a machine with an order of magnitude more processing power and 64 times (!) as much RAM lag when switching channels?
The app logic is still in Javascript, never compiled to another language.
IMHO this is perfectly fine. I have a fairly large app in react-native, and most users that have tried it are fine with its performance. Scrolling in lists and maps, being native components, is as snappy as in a real native app. I'm only having performance issues in page transitions, and I think I can fix that with a bit more work.
Haven't we moved past writing UIs in code about twenty years ago? I see your code samples, and all they look like is an improved version of the code UI creation we had in OWL, MFC, and other UI frameworks on other platforms.
Starting about 1995 we had a better way: form designers that streamed objects (note: not even auto-generated versions of code, which is not much better, but object streaming.) Your UI is then designed and manipulated largely as a graphical UI -- that's what it is -- and manually written code is reduced to tweaks or state changes.
For example: Delphi (the prototype of all modern UI frameworks); C++Builder; others. WPF may count although the generated text is ugly as :) - but it carries the concept. A NIB file on macOS. You get the idea.
I'm working at Pagedraw (https://pagedraw.io/) which attempts to solve this problem. We make a UI builder for web. It pretty much works like all the UI builders of the past, but translates constraints into divs, flexbox, and other web standard html/css. We don't have the benefit other UI builders in the past have had of compiling into our own layout system, because we refuse to force our users to use a js-based layout library or take extra dependencies which could increase bundle size.
It's only available for React Web for now, but we look forward to supporting React Native, and maybe even Proton Native in the future!
Lastly to matchbok's point:
> NIBs in macOS/iOS are horrible for development and code review.
We hope that this is a problem with NIBs, and not with UI builders in general. We believe that it's because there are no NIB diff/merge tools, so we're building branch/diff/merge into Pagedraw as a first-class feature.
Well you can always choose to roll your own layout algorithm and position everything in the DOM using absolute coordinates - e.g. https://diasli.de implements an 'auto layout' mechanism disregarding DOM layout.
Using a UI to build UI is slow and clunky. There is no "moving past" it. That's a bad way to develop stuff. We don't do it with HTML, do we? No.
Storyboards are great - they simply force separation of concerns among developers.
One person handles one part of the app, and other people keep their hands off of it.
Each person has their storyboard/collection of nib files.
Multiple people should absolutely not be tinkering with the same files randomly - obviously I hope.
As for things rearranging for 'no reason' - it'd help if people took 2 days to understand auto layout. Every person I've ever met who dislikes sql, or storyboards/auto layout etc, simply doesn't understand what is happening.
It's trivial to create a mess in auto layout, if you don't know what you're doing, just like people create cocoapod soup in every other iOS project. There is no silver bullet for curing mediocrity - just make sure you're not part of the problem :)
I review design screens and UI/UX workflows with end users.
WPF has(d?) this figured out. No drag and drop of UI elements (aka "components"); that gets you into "absolute position" hell of Windows Forms. Instead you have a DSL that you use to build the UI with grids and other standardized layout containers and the WYSIWYG view is there mostly as a preview and navigation help.
Of course their fatal mistake was having no code whatsoever in the DSL. They wanted to make it so designers would use it; designers will never use anything but Photoshop, so the other half of them that isn't resistant to learning now calls themselves frontend developers. The model binding on steroids helped some but still "inverting" an enum required 15 lines of code somewhere else to create a converter.
Only for those that never bothered to learn how to use Window Forms layouts.
https://docs.microsoft.com/en-us/dotnet/framework/winforms/c...
It's the same issue that project.pbxproj has in Xcode.
How could we? There is hardly any design tooling that matches the capabilities of native ones.
So we just give up and pretend we don't need them.
This is what I love RN so much - I can build UI in 20% of the time and effort.
Here's an interesting discussion of Delphi (2013): https://news.ycombinator.com/item?id=7613543
First, you have a visual form designer: drop a button, resize it, edit the caption, etc.
All objects like buttons, edit boxes etc are classes with properties. They live on a form, another class. The key is object streaming.
The form has instance variables: a private MyButton : TButton, for example, where TButton is the type. This list of fields is autogenerated by the IDE. However, those are created and values set not in code or managed by the IDE, but by loading from a human-readable text stream at runtime (stored as a separate file at designtime, and linked as a resource at compiletime), something like, from memory:
Form : TForm
Button : TButton
Left = 100
Top = 50
Width = 70 // etc
Caption = 'Hello'
OnClick = MyClickHandlerMethod
end;
end;
When the form loads, the object instances and their properties are created and set on the fly. A form will self-initialise it and its owned objects from that stream: it will create a TButton instance, assign it to its own Button field, set the Left and Caption properties for the button etc. That includes hooking up methods to events, which are just properties of a method pointer type. So effectively, you have a human-readable, easily editable format that is a streamed version of a class and instance/property hierarchy, which the class can recreate itself from. That is generated by a visual editor, and of course you can edit it manually. It is a very simple and clean format; as little as possible is stored. It is also very diff-able.Your code then is reduced to things like state changes or events - user clicks a button, you write code to do something.
UIs are visual. Writing a complex UI in code is inefficient (manually doing stuff you should not have to do) and with a long modification turnaround time - you can't preview what it looks like, so changes take a long time. The important leap was to design visual elements visually; to stream, so it is OO, diffable, and still human editable if you need to; and to load from a stream via reflection/RTTI.
Delphi did all that in 1995. C++Builder does all that too, in C++! It's beautiful compared even to Qt, and certainly compared to code like the original post, which reads like early nineties techniques to someone used to the above.
Allaire Homesite (one of the early HTML editors), written in Deplhi, was one of the first apps that openly ignored the pt sizing and was broken on computers with Large Fonts setting enabled. After that, everyone started ignoring the DPI, and that is what got us into today's HiDPI mess.
Yes, I was pissed of at the time. I was using Large fonts. During a short time, that option became unusable, because nobody bothered with DPI, when drag and drop UI design is so easy.
I don't see an issue with creating UI's in code, with a decent API like Qt and Gtk provide it's quite straightforward. Why should UI code be treated differently to other code?
Why should I spend 30 coding something away that is doable in a few seconds with a couple of mouse clicks?
It is not good to generalize, but most coders I have meant without any sense of UI design never used graphical tooling for doing UIs.
Because maintainability is more important than instant gratification. If you can do both then great, but IME visual designers are a maintenance headache.
I remember using GUI codegen tools in the 1990-ish era that would blow away your code changes with every GUI tweak. Interface Builder and delegates were a great solution to that problem. I just didn’t get to use them for a really long time.
It's been like that on Windows since 2006 with XAML. In fact, if you squint at typical JSX, it looks like XAML.
Disclosure: I work at Microsoft.
The crazy part is, that you can share code and eco-system components among these targets, no matter if they're native or otherwise. Here's a shell applications for instance that uses react-motion to shift stuff around: https://github.com/gaearon/react-blessed-hot-motion
Microsoft seems heavily invested in it as well (react-windows, reactXP, UI-fabric, ...).
What does dependency injection have to do with anything? There's nothing stopping you from using global variables or an event bus or something like Redux in a XAML app.
OpenLaszlo was most immediately inspired by HTML and (for data binding) XSLT. I looked at Mozart for ideas on constraints, but we ended up rolling our own design — mostly because constraints were never supposed to be a feature, so they were designed and developed incrementally, in discretely releasable baby steps.
Adobe did due diligence of the company sometime around 2002-2003 too, but that deal fell through. An Adobe PM also signed up for our beta program, initially under a pseudonym, but he eventually came clean. I’ve always been curious whether Flex/MXML was related to either of those encounters.
[1] https://en.wikipedia.org/wiki/OpenLaszlo
[2] https://ssl.weepee.org/lps-4.6.1/docs/developers/program-dev...
Today Xamarin does all this pretty well cross platform, desktop and mobile for UWP/Mac and iOS/Android.
The databinding approach is both elegant and familiar.
It certainly does look a lot like Vue Single File Components if you squint.
Damn it, didn't we just have an article on HN about creating art using CSS?!
At least when concerning all major GUI libs.
It's more like a markup driving an immediate-mode graphics API.
It works I suppose, but it's very clearly written to be an easy-to-compare example, not a realist example. To really get an idea of what it would be like to use proton native v. Qt I'd like to see a small but complete project.
Easier to read and edit is obviously subjective, but shorter is not and that front page is just straight up lying. The Qt example is most definitely shorter. What am I missing?
But if you have any suggestions let me know!
It seems to me you're making a syntax comparison and using shorter as an argument for Proton Native, yet the example is obviously not shorter so it's factually incorrect. My suggestion is you don't use shorter as an argument. Aside from being incorrect, it's probably not very useful since a few characters here and there doesn't necessarily mean one is more or less complicated than the other – which I presume is what you're really trying to convey.
I'd probably refrain from using syntax comparison (mostly a matter of preference and familiarity anyway) and instead show why Proton Native is obviously less complex than Qt (or other options, if that matters.)
import QtQuick 2.7
import QtQuick.Controls 2.2
ApplicationWindow
{
title: "Example"
Button {
height: 300
width: 300
x: 50
y: 50 // not represented in the react code for some reason
onClicked: console.log("Hello")
}
}I’m talking about this:
</Button>
</Window>
</App>
);
}
}Also, the paradigm is completely different in that react is React is déclarative whereas Qt, in this mode, is procedural. I would argue that QML would be a better comparison, and in this case I’m quite sure that qml wins.
So much for buzz words..!
import React, { Component, createElement as e } from 'react';
import { render, Window, App, Button } from 'proton-native';
function Example() {
return (
e(app, {},
e(Window, {title:"Example", size:{{w: 300, h: 300}}, menuBar={false}},
e(Button, {stretch=false}, onClick={() => console.log('Hello)}, 'Button')
)
)
);
}
render(<Example />);
If you really hate the brackets and parens you could certainly use a dialect of JS that doesn't have them, and you could cut it down to like half the length of the Qt example.But this whole discussion is silly. "Shortness" in code terms has much more to do with the number and complexity of statements, not LOC or characters. The JSX in there adds "noise" and characters, but the whole purpose is to simplify understanding code and make it readable. It's not adding any fundamental length.
The Proton example is doing a bit less than the Qt example, and for me that's a much more useful definition of shorter.
Of course, with unlimited development capacity, for each React Native app there could be a better purely native app.
Another point also often forgotten is that the user experience of a React Native app, while not as 'platformy', will be very coherent for users of multiple platforms. That can also be considered as 'better', given you are such a user.
https://github.com/wix/react-native-navigation
Edit: Replaced the word FUD with overstated, to not seem like I'm attacking the author personally.
"The last time I checked there was still no reasonable, scalable way to do complex navigation on the platform. Most third-party components are unusable six months in due to API changes."
The links are counterpoints to the complex navigation issue. Showing that libraries exist and can handle complex navigation. If you want to argue that they are going over rapid change, which is true, then that is another thing. But I'm gonna disagree with the blanket statement of "there was still no reasonable, scalable way to do complex navigation on the platform" as overstated.
As for the second point. I assume what you mean by 'third-party components', is actually third-party native modules. In which I agree the API for them doesn't seem to have stabilized yet so there is a lot of churn in native modules. But a lot of third-party components I have seen continue to work in newer versions of React Native.
Just a nitpick because I think "FUD" borders on ad hominem in the way it's sometimes used.
Again, as a React dev, I haven't encountered the cited issues and they seem a little dated, but I wouldn't call them FUD.
It's iOS-style navigation and transitions through and through.
If this project was about formalising proper stable support for Windows and macOS within React Native, that would totally make sense. But it seems more like it's trying to be an alternative, under a different name, different branding, etc.
Surely it's better to remain as one widely compatible project?
And what if you want to make a non-UWP app for accessibility or other reasons? Just your standard, straight forward Win32 GUI. Bringing the power of React to that space will still appeal to many.
I'm not sure why JIT is relevant. Neither JSC nor Node do any JITting.
http://thibaultlaurens.github.io/javascript/2013/04/29/how-t...
One thing to note, the naming convention of props differs from React Native which is a bummer. https://github.com/kusti8/proton-native/issues/9
IIRC the project is a light mapping from libui-node project to React.
BTW: It should be "protons" without an apostrophe.
class Example extends Component {
render() {
return (
<App>
<Window title="Example" size={{w: 300, h: 300}} menuBar={false}>
<Button stretchy={false} onClick={() => console.log('Hello')}>
Button
</Button>
</Window>
</App>
);
}
}
render(<Example />);
is using too many artificial parsing layers ?1) Like run JS, then there 2) parse JSX that will build virtual DOM, then 3) interpret that vDOM to 4) create physical window.
Why not just
let app = Application({params});
let window = app.window({url:"content.xml",
type: "frame" }); let button = new Button("Click me");
window.attach(button, {position: 'center'});
To me, imperative widget creation gets tedious and hard to read pretty fast. I'm not a fan of the many parsing layers involved in the JS example either, but I really appreciate the declarativity they enable.Window content can still use markup. But it is not clear why do you need it for defining Application and Window abstractions.
In browsers DOM element is a subject of style applicability and events handling. But why do you need DOM nodes for application and window ?
window = (...children) => <App><Window>{...children}</App></Window>
Over the years I've learned that some boilerplate isn't bad. In fact it means App and Window are implemented in the same abstraction that I'm using. import { createElement as e } from 'whatever'
return e(App, {}, [
e(Window, { title: 'Example', size: { w: 300, h: 300 }, menuBar: false }, [
e(Button, { stretchy: false, onClick: () => console.log('Hello') }, [
'Button'
])
])
])It is not, https://facebook.github.io/jsx/
It is handled by transpiler - one more parsing layer in loading sequence of your application.
[1]: https://developer.mozilla.org/en-US/docs/Archive/Web/E4X
There's already plenty of prior art for RN-compatible projects that target non-mobile devices (e.g. react-native-web, a half-dozen different AR and VR projects).
Sidenote as for why a UI library would wrap another UI wrapping library, Gtk is what is considered "native" on Gnome based distros.
So weight-wise, it's basically comes at the cost of native node module which is not bad compared to Electron's crazy IPC bridge back and forth communication nonsense.
And now with NAPI [1] it should be easier than ever to make node modules!
Is still really incomplete compared to libui-node, but just in case someone wants to help
);
}
}We're in a thread about a React Native for desktop implementation.. saying "React Native is React Native for Desktop" is confusing; hence my question.