Hacker News new | ask | show | jobs
by jrq 2964 days ago
I understand your frustration, but in a world with a dozen different languages to choose from for cross platform native desktop apps, there's very rarely a case to be made for electron even existing.

I'm not trying to prove your point by making the insufferable comment that you hate and already expect, so please understand I am genuinely interested:

Why would, or why should, a person interested in creating a cross platform desktop app, choose electron?

If it's just to use their favorite web components to design with, is that really a good enough reason? When GTK and Qt both provide js api capabilities, what else is there to gain?

Please understand, I'm not a web developer, I'm not familiar with most of it, but just the thought of 100+MB overhead for an app is completely unacceptable to me. But again, the benefit of using web tech is lost on me.

5 comments

Apart from VSCode, I'm also not a fan of Electron - but I do understand why people use it.

> When GTK and Qt both provide js api capabilities, what else is there to gain?

It's the HTML5. How would you write an xplat editor with GTK or QT? The obvious answer is to use Scintilla and after some Googling surrounding getting that right, you're successful! Now you want to start innovating the editor, with both the speed and bravery that the VSCode team do. Now you have problems.

As much as I despise HTML5, it does provide a canvas that behaves consistently across platforms (so long as your browser is consistent, which Electron is). I can't see why you'd use it for a music app or so forth, but rendering a text editor is a surprisingly difficult task - it does present genuine benefit in this field.

You could use OpenGL or Vulkan, but then you'd spend your life writing the UI framework and wouldn't have the xplat layer that NodeJS offers.

So what electron developers appreciate is an easily accessible markup+canvas?

Text editors are a great example, they're very difficult to get right.

I wonder why more desktop GUI platforms aren't equipped with something similar to html5->native markup.

Thanks for your comment, that clears up the question of appeal for me a bit. I can see how much frustration is saved in a project like vscode by using electron.

> html5->native markup.

I'm personally a bigger fan of XAML (done right, with MVVM) for that purpose, but it's unrealistic because XAML is dead. So ultimately I agree, there should be a browser of sorts for highly trusted apps. Electron is a runtime, it shouldn't be bundled with every app that uses it.

Maybe I should tell that to the guys that have paid my bills for the last 4 years.
I have done years of web dev, including modern React UI, as well as years in the past with Java Swing and Qt/C++, so I have a little perspective here. Electron offends my sensibilities for precisely the reasons you outlined. However, these are my thoughts:

1. It enables a large swatch of people that have never done desktop development (which has a learning curve that is hard to climb if you aren't paid to do it) to build cool stuff and ship it. Without Electron, we'd be left with nothing. If nothing is truly better than something with Electron, then this won't be a compelling point. However I'd rather have stuff that I ignore than to not have stuff.

2. Performance in electron can be decent. It isn't always because of bloat and poor implementation, but that can be true of native apps as well (especially java-based ones). The download size is laughable, but hard drives are reasonably sized these days so this is less of a pragmatic concern, and more of an ideological purity concern.

3. The modern paradigm that React brings to the table can genuinely be a better dev experience than the traditional frameworks. The benefits of "always re-render" would have fixed numerous bugs that I dealt with in UI land regarding state and dealing with changing state. Developer happiness is worth a lot when the project is open-source, unfunded, and done by someone with passion (which is how almost all open source starts).

4. I think it's temporary. There's projects like Proton that are already looking at how to get the best of React/JS on the desktop without the bloat of shipping a web browser with your app. The future looks bright.

NOTE for people devving on electron: Please be more conscious of memory usage and potential memory leaks. Desktop apps are often long-running and you've got to pay attention to resource usage and the memory leak traps that can cause your app to gobble up insane amounts of memory (cough slack cough)

Thanks for these! Proton is interesting, I think the space has a lot of potential.

I'm concerned that someday html might be the standard for gui system markups, that could go wrong easily.

Part of my perspective on this, maybe yours as well, is the amount of projects in electron that just didn't need to exist in the first place. Guys writing email clients, for example. Nobody is going to use something like that. Casual users will prefer the browser and power users need mega-apps like Thunderbird to be productive enough.

I've been hoping Elm guy would try and bring Elm to Qt or OpenGL or something like that. I think desktop apps have a lot to learn from FRP, which is prevalent in web tech, or at least more so than it has been in the past.

It almost reminds me of Emacs, ya know? Everything and the kitchen sink, and the plumber, and his truck, and the Home Depot. Unnecessary!

Anyways thanks for your comments. Your experience is helpful!

Definitely, and thank you for your perspective! I totally agree WRT FRP. I have a friend that swears by FRP on Android. I believe he uses RxJava and RxKotlin.

Something like Elm coming to Qt would be great!

I've programmed in Electron and GTK (about 8 years ago), so can only compare those two.

GTK claims to be cross platform, but the windows support is (at least was), awful. Lots of special casing required. Also hi dpi screens never worked right. Also just getting tge dev environment configured on mac, windows and linux was a multi day undertakung and required weird dodgy mingw gcc builds.

With electron, the multi platform is taken seriously. It just works. Also, because electron doesnt try to look like each OS's default toolkit, your app looks the same in all 3 major OSes, so you dont need piles of os specific GUI fine tuning code.

> because electron doesnt try to look like each OS's default toolkit, your app looks the same in all 3 major OSes

That's a significant selling point actually. When I did Qt and also Swing, this was something that got me often. Making something look just right with polish gets to be quite difficult without having tons of platform specific code and logic.

There aren't a dozen different languages. I'm not even sure that there's a single one with an attractive story on Windows + macOS + Linux. Gtk doesn't work well on anything other than Linux/Unix (not macOS).

So it's mostly Qt vs Electron. Having to compile different binaries for every Linux distro and version makes Qt a non-starter for most. And if you're going to compile it statically to try to avoid that dynamic linking nightmare, you just added more bloat to your download than Electron.

Qt is hardly a popular toolkit for Windows and macOS apps.

And if I use Electron and React, I get to add native-ish mobile apps for little extra work by using React Native there.

Because most cross-platform desktop GUI kits are terrible. Everything that's not paid requires a lot of fiddling with C++ bindings and obscure build scripts. Electron is built on Chrome which has billions of dollars backing it. If you want something that's easy to use (and not having to spend too much time thinking about license compliance), looks pretty and works well, your options are pretty limited. Say what you must about Google and profiting from ads but electron is one of the only few full-featured GUI frameworks that allows for simple statically linked app distribution. For free.