Say no to Electron: use JavaFX to write a fast, responsive desktop app
sites.google.com
sites.google.com
You know what Electron has brought us? It's brought the Linux desktop reliable feature parity with other platforms. Fat chance Visual Studio Code (often hailed as "one of the best-optimized electron apps") would have existed on Linux without Electron.
Discord, another fantastic Electron app, is functionally identical on web and desktop (all platforms), feels fantastic on Linux, no issues at all. What are the odds I would have a functional Text/Voice/Video chat Linux desktop client for Discord if Electron didn't exist? How much time would have had to be spent reverse-engineering the protocol then implementing a decent UI for it all?
Obviously you shouldn't use Electron for certain things. If your app is tiny especially, you'll be better served with a leaner framework. But that's nothing new.
Electron has given desktop developers access to the web's fantastic tooling and iteration speed, and web developers access to the desktop market. It's given the ability and incentives to all those developers who might not have touched Linux before to make a Linux release alongside the rest.
If you don't like how Electron performs, your time would be better spent optimizing it than seeking out Java frameworks, which work atrociously bad on anything that isn't the author's platform (if even that).
JavaFX apps work just fine on Linux. Not even fine, they work well. I know because I've written them and tested them on Linux. And not just trivial toy apps: the app I wrote was a full blown peer to peer app with an integrated Bitcoin wallet, a Twitter Bootstrap themed UI, file associations, visual effects like animated Gaussian blurs and an integrated auto-update framework.
There's nothing magic about Electron. It's just another desktop app toolkit. There's no good reason to use it except developer familiarity with HTML. It gives you all the disadvantages of desktop distribution (you have to provide your own auto update framework, get users to download the app) but with none of the advantages like great tooling, great languages, UI builders and so on.
I hate Electron apps but I can see why people do it. It's very tempting to be able write desktop apps with the web's best frontend technologies.
Its funny you say this while using java
So java 9, Kotlin, Scala or kawa (scheme), abcl (common lisp), clojure (nu lisp:), jython, jruby. While there are compile-to-js languages too (including Kotlin, Scala, clojure :) - there is quite a lot more history around jre/jvm languages for production desktop use.
Because "god forbid" anyone use technologies associated with java? FUD at its finest.
> Fat chance Visual Studio Code (often hailed as "one of the best-optimized electron apps") would have existed on Linux without Electron.
I just use IntelliJ IDEA. It's ten times faster and ten times more powerful than Visual Studio Code. And it's written with java swing.
VSCode is easily 10x faster than IntelliJ. If I'm writing Java I'll happily use IntelliJ but anything else it's VSCode or vim.
Actually, if Mozilla's Servo tech gets integrated into something like Electron, then we will have some serious performance capabilities surpassing pretty much anything else comparable.
I joke with my coworkers that I know they’ve fired up IDEA because I can hear it. Whenever it’s on, their fans are dialed up to full blast.
But I've never found it slow in any respect that matters for doing actual work. For everything that matters (opening files, project-wide search/replace, refactoring, typing latency, looking up docs, code navigation etc) it's easily competitive with lightweight editors.
I'm convinced all of the mud slung on Java is due to enterprise programs and other software not motivated by quality (more of a "you have no choice but to use this to interact with our hardware/service and we CBA to make multi platform so you're stuck with our lazy java. Oh, and we come from the school of abstracting things to hell because creating more red tape impresses upper management.")
IntelliJ is I think the first application that showed me that Java is Good, Actually™ by delivering on those mythical promises of compatibility and speed.
I've recently written a decent-size Qt app (QtWidgets, not QML) and the problem is the language. C++ leaves a lot to be desired especially coming from higher level languages. If you look around at language bindings, the only quality one I can find is Python and I want to avoid that too (I don't want to build a large app in a dynamic lang). Couldn't use Go, I needed MSVC to interoperate. Rust bindings had drawbacks or were incomplete. Etc. (I probably need to revisit D's Qt binding)
I just want a full-featured (i.e. not QML) widget framework in Rust, Go, D, or some other high-level non-VM cross-platform language. I'd even take C bindings because we can work from there. And I want the widgets to appear native. C# + WinForms would be great if it worked great on non-Windows and was easy to interoperate with third party C-level widgets. WxWidgets is C++ or dyn lang (though there was a C binding maintained by Haskell devs IIRC), Gtk doesn't look very native, etc.
Widget-based desktop development will continue to lose to these alternatives while there is not a good widget library on a good sans-baggage language.
Edit: Just saw https://github.com/christolliday/limn (https://www.reddit.com/r/rust/comments/73w227/limn_gui_libra...) ...a good start!
what are you missing with QML ?
However, it does let people hit 4 platforms way quicker than even two, which is a huge deal. And while I'm working out the kinks in my Qt app, the Javascript dev has a version anyone with a browser can use on anything right away, even if the desktop version isn't ready yet.
†Pouring one out for HyperCard. I miss that wonderland.
Edit: Damn you auto-markdown.
There must be irony here. The web development plateform is easy to get in, but hard to master: too many languages are involved (html, css, server side, javascript) and most didn’t have some really useful features until very recently (css grid for instance).
Then you have the language creep (Typescript, Dart or anything to paliate JS deficiencies; LESS/SASS), the JS framework creep, the libraries decay, etc.
I failed to see how this is ‘fantastic’ in regards to a language such as C#/F# that allow you to build desktop app very easily. If multiplatform support is not a requirment, the desktop languages and tooling are way ahead in term a ease of use.
That is totally a thing in Java too. Languages: Groovy, Kotlin, Scala. Framework: GWT, Spring, Struts, Vaadin, Grails. Libraries decay: commons, apache, different parsers, different db drivers.
On top of that though, you need to think about your JVM? What dependency manager: Ant, Maven or Gradle. Then figure out which JDK to use, cause that's a thing. Then figure stuff out like facets. Sure this is more IDE field but the fact Java app architecture can be so whack that something like 'facets' needed to be abstracted only proves my point.
> If multiplatform support is not a requirment, the desktop languages and tooling are way ahead in term a ease of use.
Ahead with the size of muddle yes. Web stack is just very good and fast at emulating the amount of it.
I think you are confusing the JVM with Java. However, comparing languages needed for web development to available JVM languages is comparing apples-to-oranges. With web development you have to use different languages in the same app to accomplish anything. In a app you are using the JVM for you can pick one language and stick with it.
> Then figure stuff out like facets.
A "facet" has absolutely nothing to do with Java. The term "facet" is a term used by IntelliJ to configure adding features to your project. IntelliJ configures all of these on its own, I never even have to think about them (it actually took me a bit to even figure out what you meant by "facet").
Is this some kind of joke? VS Code is a glorified text editor that ate your CPU trying to blink the cursor: https://github.com/Microsoft/vscode/issues/22900
Microsoft has a real IDE, and it ain't written in JS.
I had to check the date on this article to see if it was from 2007 or something. Under no circumstances does java "just work", its an insane mess of java shipped with the os, being updated, and people not updating due to oracle trying to force feed crapware as part of their installers/updaters. I, for one, do not live in a world that resembles anything like java jars "just working".
The leaks in the operating system abstraction Java gives you are really quite small. I wrote my entire app on macOS and tested on Linux/Windows only right at the end - after about 8 months of full time dev work I spent about a day addressing platform specific issues. That's pretty good.
Now compare that to the mess that web browsers were and still are. It's better than it once was, but you're going to have to check every single feature of HTML5 you use to figure out which browsers implement it, which don't, which use vendor prefixes still, which only half implement it, which don't but can be shimmed using big blobs of JavaScript and so on. The web absolutely doesn't "just work": you will spend more far time working around browser specific issues than you will spend dealing with OS specific issues in Java.
I'm confused at this comparison in terms of Electron. Do you have to worry about any of that when doing an Electron app? Or were you making a comparison between JavaFX and web dev?
Side note here: do you track security vulnerabilities of the shipped JRE and provide updates when it happens?
Too often, I've seen java applications shipping obsolete and vulnerable JRE. And in some cases, I've seen not consistent versions across a product line.
Also wasn't there some unknowns about the right to redistribute the Oracle JRE?
Nope, Oracle clearly says you can in their FAQ:
There's tools for that and i'm pretty sure just writing plain html and css or some compile-to-js would have shaved off significant time from that 8 month full dev time.
Note that even in 8 you can do a DCE pass over the code and erase files you know you won't need from the JRE image by hand. I did this and shrank the size of the download by about half. The JavaScript world calls this "tree shaking", you can use ProGuard to do it in Java but it's a bit fiddly to set up.
https://docs.microsoft.com/en-us/dotnet/core/deploying/deplo...
Sun did that damage.
For details, see "JavaFX support is in upstream OpenJDK 9 but missing in Ubuntu OpenJDK 9" (https://bugs.launchpad.net/ubuntu/+source/openjdk-9/+bug/172...).
This article so thoroughly misses the point of Electron. Furthermore the author's snark and condescension just serve to antagonize and attack rather than making any semblance of a point.
People choose Electron because it's easy to work with for people who are already comfortable with JavaScript. JS devs get to use tools like React, TypeScript, Webpack, Babel, and other tools they already understand and like. You have the entire wealth of tools of npm at your disposal. And since it's JS, you can share code between Electron, your website, and your Node server.
In addition to that, HTML, CSS, and JavaScript writing UIs is something thousands of us do every day do for a living. Being able to do that for a desktop application unlocked a whole world of development that previously was closed to only those comfortable with Objective C, C++, Java, and the like.
The author does a woefully inadequate job of explaining that choosing Electron is a _tradeoff_. You're trading a larger memory footprint, bigger artifact to distribute, and some extra performance challenges for the ability to write your application like a website in CSS, HTML and JS and have it work on every OS that Electron supports. For many this tradeoff is unacceptable but it's either incompetence or idiocy to not see that this tradeoff works for many of us.
I am not a web developer, so I may be way off base.
I don't write frontend / GUIs for a living (I tend to do C and Python). But I have done work with GTK+ and Qt, and I have done work with Angular and other random JS frameworks, and the web is so good.
All the complaining about the web is from people who just want it to be better.
This is sort of an unfair comparison - the JavaFX one is mainly smaller because it doesn't include the distribution of Java and all the libraries, which is if I recall correctly about 200 MB, while Electron commonly includes all libraries and the renderer. I will give you that the Java distribution can at least be shared by many applications, but you can definitely get into some nasty versioning situations with that.
On the other hand, if you were to compare this with say a Qt application, it'd be about ~20MB all in, ~10MB if UPX'd, no external dependencies needed. Or just the size of your tiny executable if you're working on a Linux distro that ships those deps already.
This means you can ship a considerably smaller built in JRE with your app, if you don't want to depend on a system JRE.
javapackager (uses jlink): https://docs.oracle.com/javase/9/deploy/self-contained-appli...
Most of the Java runtime is not actually used by most apps so the new modular Java 9 should produce much smaller installs, but I haven't tried it yet.
The Chrome dev tools alone are pretty incredible. Getting that much detail in your debug environment, paint cycles, render times, animation effects, and quick style experimentation is a huge deal.
The package ecosystem for JS is also an enormous advantage. Having access to data layer systems like Redux & the Redux dev tools, as well as any module designed to run on Node.js really helps ensure an actively developed ecosystem that abstracts more and more away from the end application developer.
Finally, I argue that performance bottlenecks are rarely an issue of the javascript. V8 is extremely fast and only getting faster. Most bottlenecks come from doing something dumb during rendering, or tying up a process reading from disk. These are issues that happen on all app platforms. The big difference is that Electron gives you to tools to effectively debug and optimize these, plus a HUGE wealth of online resources & tutorials to help new developers jankbust.
VSCode is far faster than any other IDE I've used, and even beats VIM in terminal in terms of responsiveness (altough I suspect this is not VIM's fault).
Discord is overall a great application, and quite responsive.
Both are slightly bloated in terms of memory, from what I supect they could be. But not nearly as bloated as many of the competing Java and C++ applications.
I too like discord and VSCode, but VSCode uses far more resources than sublime, with the tradeoff being that it's more easily extensible and has a faster release cycle(which may or may not be related to team size). VIM locally is obviously also going to be much faster and capable of opening far larger files than VSCode.
To catch a single press of the escape key, vim needs to wait a little bit to make sure it's not the start of an escape sequence. Sometimes that delay is configured too generous and becomes noticeable, especially when chaining applications (like running vim in tmux).
For real?
The other thing of course is that Electron apps start out as web applications. So they already work perfectly in a browser.
Are they going to fragment the code-base with Java to introduce a desktop client? Are they going to hire another enterprise Java dev, who most likely isn't familiar with the rest of the stack?
The rise of Electron is fundamentally driven by the cost effectiveness of the wide availability of developers and community support.
But Qt has rust bindings, so that’s good to learn!
"Install this runtime, then you can install this app. Oh and that auto updater that is atrocious? You can thank us for having it. Thanks for being a loyal customer!"
If I was trying to sell someone who uses Electron on an alternative it'd definitely be JavaFx, maybe Qt with QML if they knew C++.
'nuff said.
Java isn't new or unpopular- if people wanted to use it, they would
Many IDEs have some sort of visual GUI layout tool, but the nature of HTML+CSS makes it a far leakier abstraction less suited to visual positioning.
So here's what i've found people trip up with JavaFX mostly.
1) FXML. Why do you need so much information just to view "Hello world". You need to define a scene, then you need to define what's inside the scene (You'll need to go look up a reference guide on JavaFX to find what objects you can attach just to get started), then you need to describe that a text node is connected to the thing inside the scene. For HTML it's always gonna be <html><body></body></html>. Inside the body it doesn't matter what structure you create, you'll be cutting off "sections" with plain html+css. HTML5 got it's canvas if you need more advanced functionality. Why would people who have been taught to use canvas and DOM revert to this?
2) Custom CSS. Fantastic, more syntactic sugar and another reference guide to search through... people get effects/animations with greensock or css nowadays, it's fairly competent stuff and frankly more intuitive. Just a gem from the reference: background: white; -fx-text-fill: ladder(background, white 49%, black 50%);
Without reading the reference I'm thinking it's filling the color. What does ladder and it's arguments mean I would have no idea. What does is this: "Use the following if you want the text color to be black or white depending upon the brightness of the background." – right, cool but there's filters and stuff made for this very thing in plain old CSS.
3) JVM hot code reload. The entire section is confusing to people using Node that learned to implement a watcher in Tutorial 1 of setting up package.json. Good luck explaining intricacies of JVM to grads that struggled to get bare bones Java application running in Eclipse. "I find it hard to believe that anyone would prefer the webstack to working with a sane environment like the JVM." – I profusely disagree. The fact you need to have a virtual machine for your code to execute is a lot for people outside the bubble to comprehend. The fact you have two types of dependencies, runtime and compile, already confuse new people coming into the field. Gradle which is supposed to make lives easier is still way more confusing than fiddling with package.json. It's perhaps not Gradle's fault, I think the blame is more with veteran developers that like to be 'clever' and manage to obfuscate something as simple as launching an application.
4) SceneBuilder. "It can be integrated into all Java IDEs, making it easy to create new views.". What the author has forgotten to mention, is that it can be a pain to use and integrate (Haven't tried this in IntelliJ and i'm sure it's better there but it's still more hassle than opening your flavor of browser inspection). You'll most likely end up ditching the GUI and do everything programmatically, at which point you'll ask yourself why are you doing css and js in Java. The example in the article is a simple "Hello World". Anything more complex and you'll find people falling into the habit of doing everything inside of Java.
5) ScenicView. "To start it with your application, just download the jar and pass the option -javaagent:/path-to/scenicView.jar to the JVM." – that line might as well be written in Chinese if you're a person coming from the Node scene.
6) JavaFX does not automatically refresh stylesheets. You need to build a whole seperate function and implementation just to refresh a stylesheet. "This works in Mac, Windows and Linux Mint. But this was one of the only two problems I had related to differences in OS's (the other one was the icon in the system tray on Mac does not work, but there is an ugly workaround for that). JavaFX abstracts that away pretty well, most of the time!". Well that's reassuring there is an iffy solution to a problem that shouldn't be there to begin with.
I also feel the author is quick to throw anyone using electron under the hipster title and then proceeds to call the webstack a mess yet ignoring the mess that Java is. Need I remind you why Node stuff was so popular? Because people required entire days to figure out how to get a simple ToDo Spring application working. And Spring is supposed to be easy. Think about that. You need to spend dev time on something as obscure as 'JVM tuning' at one point or another. Or fixing some bizarre leak/overflow because hurr-durr imperative programming. And the 20 years of patterns and best practices wasn't good enough. We have shit like JPerf to figure out why all those stern-toned articles still lead to shitty code and JRebel to sweep the problem under a rug.
"We've been writing desktop apps for decades. The web, on the other hand, only really got started less than 20 years ago, and most of that time it was only used for serving documents and animated gifs, not creating full-fledged applications, or even simple ones! To think that the web stack would be used to create desktop applications 10 years ago would be unthinkable." – And here we are with Java still remaining the clusterfuck that it is.
"If people are preferring to ship a full web browser with their apps just so they can use great tools such as JavaScript (sarcasm) to build them, something must have gone terribly wrong." – yeah, that something was the JVM. Kinda funny we now have all this compile-to-js stuff when there's still uppity aura revolving around JS. Heck I remember having trouble with just the JRE back when I hadn't learned any programming.
There are reasons to pick your tools. Sometimes speed of development and being able to use your pool of developers existing skill sets effectively is one of them. If you have a bunch of web developers and need a desktop app then electron is something you might want to seriously consider. ESPECIALLY if you don't have unlimited time to get the product out to market. Electron is not a one size fits all choice and conversely neither are the frameworks the author is proposing. Decide what you need and make your choice based upon those needs.
I am building an electron app as we speak. Its not without its challenges and there is no doubt that native approaches would trump it in some respects but it literally does everything I need it to do. Better yet, I can hand this off to my team who all have a development background and any one of them can jump in and be able to contribute in a meaningful manner within a day or two of groking the codebase.
I guess my point is, lets stop bagging on technologies for the sake of it. Every single one of them involves trade offs. Effective developers weigh those against the problem they are trying to solve and pull the trigger on the one that gets the job done best.
As a language, I find java is much better designed than Java Script.
Not much more verbose than it needs to be explicit.
"Explicit is better than implicit."
PEP 20, Zen of Python