Hacker News new | ask | show | jobs
by pwdisswordfish4 2035 days ago
> I would never attempt to implement something like this in Qt or GTK

In fact, you can write GTK apps in JS. A year or two before Electron came along, the Gnome folks had the foresight to declare that JS would be the language of choice for promoting GTK and Gnome app development, with the option to drop back to C otherwise. This caused a minor controversy, where the community decided to rage against this effort and essentially rejected it. Here we are then, instead.

Rather than the "default" toolkit of choice in 2020 being GTK, which is cross-platform, provides an opportunity to get closer to "native", and has the roots and traditions of pre-GitHub FOSS, an vacuum was left wide open—unfilled due to the internal revolt/denial of the Linux desktop crowd. So the NodeJS and web developer community swooped in and filled it, with their dubious sui generis practices pushed to the forefront instead, and the world is shipping apps in browser runtime containers.

2 comments

> In fact, you can write GTK apps in JS.

I'll eat my hat if it's as easy to write a hello world in GTK as it is in Electron/nw.js.

Keep in mind that with Electron/nw.js I download the toolkit binary and then simply declare an arbitrary webpage or js file filled with arbitrary modern HTML5 to be my "main" page/script. That means any frontend dev can immediately get a "hello world" running with no extra tooling and immediately access the full dev environment they are used to. Aside from the json file they don't even have to learn any of the non-HTML5 APIs (which, btw, are typically where the most nefarious bugs live in these toolkits).

What is more, the dev can immediately bring in any of the zillion frameworks they depend on to pad strings or whatever.

I'm guessing GTK has a way to hook into its own API through javascript. But if it's anything more than a single call to create a window and fill its webview with a page (or execute a js in its context), it's already more complicated and electron/nw.js wins.

Edit: typo

Perhaps you should try a hello world GTK JS app instead of speculating about how it surely will confirm your biases. It would've taken you less time type "hello world gtk javascript" into a search engine and copy and paste the snippet into a file than writing out that bad faith argument.

> Keep in mind that with Electron/nw.js I download the toolkit binary and then simply declare an arbitrary webpage or js file filled with arbitrary modern HTML5 to be my "main" page/script.

I don't know why you assume that GJS is any different. Well, actually it is different: you don't have to "declare" any file. You can open up a file hello.js, write your code, and... there it is, in a dozen SLOC. (If you really wanted to, you could write an entire app in that one file.)

Not that any of this is even relevant, because you totally misread my comment. It was not about how GJS is better than Electron and the Electron folks just won't admit it. It was about how Electron is better than whatever the JS-hating GTK developers wanted, but they were too shortsighted to see the future we were going to end up in with or without their endorsement. So your kneejerk defense of your tribe is off the mark.

> there it is, in a dozen SLOC

https://developer.gnome.org/gnome-devel-demos/stable/hello-w...

The actual file is 42 lines there, which includes a shebang and a bunch of calls to GTK stuff.

And that is my point-- it's 42 lines too long to matter whether or not we travel back in time to beat back the "JS-hating GTK developers." Because as it turns out, most devs are not looking for a way to use GTK from their favorite language Javascript. They just want to continue their frontend development in a box as if they are simply developing for the web, and then have the results show up as the GUI for a cross-platform desktop application.

It's clear what your point is. There was no need to explain. You want to put your thumb on the scale and confirm your biases.

> The actual file is 42 lines there

Okay? If you encounter an argument "There exists an X", proving it wrong is not as trivial as pointing out "I can show there (also) exists a Y".

I wrote what I wrote for a reason. Write such a hello world program in a mainstream idiomatic style that most closely resembles the way a JS programmer would write, and a GTK hello world app is (shocker!)... 12 SLOC, as mentioned:

  $ ls -l ./scratch/hello.js # written yesterday
  -rwxrwxr-x 1 asmithee asmithee 402 Nov 20 13:54 ./scratch/hello.js

  $ cloc ./scratch/hello.js | \
  >   grep -ie javascript | \
  >   sed "s/ \( \+[0-9]\+\)\{3,3\}/ /g"
  Javascript              12

  $ cat ./scratch/hello.js
  const Gtk = imports.gi.Gtk;

  let mainWindow = null;
  let app = new Gtk.Application();

  app.connect("startup", function buildUI() {
    const text = "Hello, World";
    mainWindow = new Gtk.ApplicationWindow({
      application: app, title: text
    });
    mainWindow.add(new Gtk.Label({ label: text }));
  });

  app.connect("activate", () => { mainWindow.show_all() });
  app.run(ARGV);
> includes a shebang

Your thumb is on the scale. No shebang is necessary, and as you pointed out yourself, the equivalent in the Electron world is to 'simply declare an arbitrary webpage or js file filled with arbitrary modern HTML5 to be my "main" page/script'. And speaking of package.json...

> a bunch of calls to GTK stuff

Your thumb is on the scale. Electron developers learn how to deal with "Electron stuff". And, hello? JSX? React? These are things that are used extensively in this space and come with their own complexities and have to be learned. (And neither are even inherently Web things. They're inventions of "framework" people and live entirely in that layer.)

> And that is my point-- it's 42 lines too long

Your thumb is on the scale. There is no equivalent Electron app that is 0 lines long. And let's talk about the untold number of projects whose package.json require many more lines, even for small, trivial, or incomplete programs. That's package.json alone, i.e., before we even get to writing code that actually does anything. Besides that, the community around NodeJS is renowned for bloat and esoteric tooling. As a concrete exercise, take a look at any random repo on GitHub, and you're likely to find the root of the source tree filled a dozen or more auxiliary files. Simplicity is a strength, but it's not one valued very highly by the people who've ended up writing Electron apps and participating in the larger NodeJS community.

In any case, regardless of this stupid (stupid!) attempt at a takedown, you can't ignore that (a) you're responding, as mentioned before, to an argument you're imagining rather than the one anyone is actually making, (b) even if your response were on-target, the argument in it is anachronistic. To be able to "continue" the tendencies they've settled into now in 2020 is an impossible constraint when the entire context of this subthread is how Gnome folks' actions in 2011 could have led to a drastically outcome for how mainstream, cross-platform apps written in JS are developed. To insist that Electron is the best fit for a bunch of developers who are used to and comfortable with writing Electron apps is not insightful, it's just begging the question.

GTK is barely cross-platform. It's an utter pain to get anything usable in either Windows or macOS. It also doesn't look native on either platform, especially Windows though, because of the default Aidwata theme.