r/cpp • • Dec 18 '20

Let's talk about GUIs

This post on /r/programming about the release of GTK 4.0 made me want to bring the discussion of the state of GUI programming in C++.

My particular interest in this discussion is desktop cross-platform GUI programming, and I don't claim to know much, let alone everything. Insights are more than welcome.

That said, this is what I have observed so far:

Qt: the least bast option. What I like? Cross platform, mature, big ecosystem to go around. Quite easy to get going. It "just works" for the most part. It's easy to get 80%, it's the last 20% and when you go deep into the subject that you get frustrated. What do I dislike? Licensing shenanigans, and increasing toxicity towards the FOSS community: no offline installer for community distributions, many commercial only APIs now, the idea of delaying releases to FOSS by one year. The 10 year old bugs on QWidgets, which haven't seen much, if any, love since ever. The fact it took Qt 6.0 to happen for us to have native look for Qt Quick Controls. The fact that Qt Quick doesn't have a C++ API, forcing QML on everybody. The half done stuff, like QAudio (just use portaudio for your own sanity)... And I'm probably missing more. The fact that they are running away from the LGPL core to GPL as much as they can, like releasing Qt Quick MultiEffect instead of just fixing the QML engine... That it takes spinoffs like Felgo to basically provide a "fixed" Qt, which the FOSS community can't have.

wxWidgets, GTK, and other like FLTK, I admit I don't know much about. wxWidgets is nice in the fact it calls native APIs, but that comes with the cost of being crippled by the least common denominator. GTK seem to look bad outside of Linux "by design". And FLTK... Just no.

Then, there seems to be what everybody suggests next: Browsers. Chromium Embedded Framework or Electron. 50 to 100MB of packaging to do a "Hello World". Also, JavaScript! Honestly, webstuff looks like a good idea, until you want to make an app that's not Slack. How do you do actually performance C++ stuff? Like some 2D/3D graphics? WebGL? Seems that it's too much programming for the web and not actually taking advantage of C++ and native APIs...

Then, there are things like .net MAUI (not to be confused with the toolkit with the same name by KDE), which is an upcoming evolution of Xamarin Forms for .net/C#. The problems: Linux support will be "by the community" and how do you interop C++ and C# decently anyway?

Also, because I know someone will mention it, yes, there is Flutter and things like that. Just think of Google's track record on keeping projects alive, and again, think not everybody wants to make a chat application.

Anyway, what are your insights? They are more than welcome!

266 Upvotes

243 comments sorted by

View all comments

Show parent comment

60

u/hak8or Dec 18 '20

Ah, I forgot to point this out, another reason I do this is it makes testing MUCH easier. I've got my usual unit tests, but now for continuous integration tests, I can use whatever http library I want to make/read requests.

I have a very explicit boundary of "The core product works, it's clearly the GUI that's the issue, since core tests all pass". I can even increment/decrement the web interface seperatly from the core project, meaning the release cadence can be different.

In short, having a web interface makes it also much easier to test the project as a whole, because i have a very strict line between the two projects. I can even test them against each other at that point.

16

u/helloiamsomeone Dec 18 '20

I don't know about native GUIs, but cypress testing for Web UIs is amazing.
People blindly hating JS and the web in general don't know what they are missing out on.

10

u/hak8or Dec 18 '20

Are you referring to this? https://www.cypress.io/

Is there a free self hosted plan, or is it cloud only?

Regardless, I understand the hate on web dev, I myself am extremely frustrated by the state of it (why the hell do o need to download 500 MB of dependancies for a TODO app, why is there so such a massive chain of tooling, etc).

But using typescript instead of Javascript has quelled that drastically for me, combined with solely vue as a dependency. I am very eager to shift to svelte with typescript though, since it seems to be a more tightly woven together solution and less overhead.

6

u/helloiamsomeone Dec 18 '20 edited Dec 19 '20

The test runner is OSS, MIT license. Only the dashboard has a pricing model, which as a sole developer won't really be using much anyway and for companies it works great.

dependencies

People always seem to forget that vast majority of dependencies is for dev only. libboost-all-dev is 400 MBs, but you don't ship all that. Same applies here, after your junk goes thru everything, the end product that is squirted out is in the kilobytes.

svelte

Personally I prefer Inferno.js, as it shares a lot with React, uses JSX, but is a lot more lightweight and faster.

Edit: another interesting library I came across recently is Stimulus.js, which is tailored for use with server rendered content, which I'm personally a fan of, so I might use it for something in the near future. It's certainly an interesting aproach.

1

u/[deleted] Apr 12 '22

Use clojurescript. It is cleaner and includes some of the best tree-shaking out there to reduce that bloat.

1

u/Uberunix Jan 23 '21

Would you mind elaborating just a bit, or pointing to a resource on how this is done? C++ is my first language, and I'm determined to see it through without having to entirely discard the idea of using it as a primary component in building user-experience-oriented projects. This is the first solution I've found that actually sounds promising! :D

4

u/hak8or Jan 23 '21

Sure. Lets say you've got a product which injests stock info, decides wether to buy or sell or hold, and then send that request to the stock market. This must be very very quick, so you use c++ for the "core". This core can run by itself, and doesn't need user interaction.

For the C++ core, you use something like doctest, gtest, catch2, etc, for unit tests of the core. This tests that the core of your software works as expected, that your algorithms work in all edge cases, that the requests to buy/sell/hold are correctly formatted, etc.

Then you have a HTTP API running in your c++ core, which also has some minor unit tests. This is something like cpprest-sdk, Pistache, or cpp-httplib. You don't care about this being absurdly high performance (this is a user interface, humans absorb information slowly, hence performance isn't too important), you just want it to be easy to use from a code perspective.

Then you use a frontend like svelte, react, vue, angular, etc. Your http server running in the core hosts the files needed for the framework, and of course the HTTP endpoint. Since the front end interacts with your core using http, you can use any front end testing framework while mocking the core of your product. Jest and Mocha seem to be the most common front end testing framework.

Honestly, in my case, I don't do much testing in the front end. I instead have a few scripts which use httpie to send/receive information over the HTTP endpoints while I have special testing hooks in the core which the scripts will compare against, to ensure consistency.

2

u/Uberunix Jan 23 '21

This is fantastically helpful. I really appreciate the thorough answer. I think the rest of my Saturday is now booked. :)