Moc myths debunked
woboq.com
woboq.com
The major issue with moc is that it is evidence that Qt does not think of itself as just another C++ library that you can plug in to your code, but that it tries to be the programming environment and the fact that it uses C++ is just an implementation detail. Moc is only the most visible of the symptom of the underlying philosophy. It is also evidenced in the QCollections and by such things as QThread which duplicate much of the C++11 functionality.
When I evaluate a library for my project, I want it to think of itself as "just another C++ library", not "The Framework that you base everything in your application around".
Qt is a great illustration of Joe Armstrong's quote "You wanted a banana but what you got was a gorilla holding the banana and the entire jungle."
If one wants to use Qt as a library, I think one can ignore the moc now that lambdas can be used as slots in a signal-slot relationship. Now that the standard C++ lib is high quality on most platforms, one could also ignore the threads/containers.
It reminds me of the argument that systemd is problematic because it's too big and complex. Well, sometimes it makes sense to write a complex system for the sake of ensuring that many complex components interoperate with ease, and system-wide changes can be coordinated between the libraries.
That's the wrong question. The right question is: what are you going to do, when you need to use 2-3-4-5 libraries and each one of them insist on using it's own primitives, collections, object hierarchies, etc. Are you going to spend your youth just writing shims to marshall data among them?
Yeah, it's a GUI App Framework, not a GUI library. Yeah, it would be hard for 2-3-4-5 App Frameworks to co-exist. But how often would that ever come up? Frameworks, unlike libraries, aren't intended to be mix-and-match. Complaining about that is like complaining that water is wet.
The answer to your question is: yes. Usually you're going to do some transformation or processing when moving from one type to the other, so you just fold the conversion into that. It's stupid and you roll your eyes and you just kind of carry on.
That's exactly the point :). It is not only C++, but also C problem. Maybe I've grown coddled with Java, Python and a few other languages, where the third party libraries do agree on the types they use.
I agree with other parts of your post, but not this. How is Qt's collections thread safe in any way? And won't that be a huge performance cost, since most of the time, collections do not need to be thread safe?
> Many Qt classes are reentrant, but they are not made thread-safe, because making them thread-safe would incur the extra overhead of repeatedly locking and unlocking a QMutex. ...
> Some Qt classes and functions are thread-safe. These are mainly the thread-related classes (e.g. QMutex) and fundamental functions (e.g. QCoreApplication::postEvent()).
In all fairness to Qt, the original version of the library predates the ISO approval of C++11 by 16 years! Much of the functionality the library provides was not even close to being available in the c++ standard libraries for many of the years since it was first released.
I understand if Qt is not your cup of tea, but many successful applications have been written with it, and a lot of that is due to the breadth of functionality the library provides (and in a cross-platform way). It's a tool like anything else, and I don't think it deserves to be dismissed out-of-hand.
moc (specifically) has a long track record that I would expect this to be solved -- no experience myself -- but regardless of how easy it is to add another build step, most precompilation stages are correlated with reduced tool functionality.
So using moc isn't ok as it ties the application to an extra tool, but using features that tie the application to a specific compiler is ok.
Moc was introduced at a time that C++ really did not have the built-in features necessary to create a framework like Qt. Since then, a few things have happened. First, C++ itself has (very) slowly gained some of those features. Second, the Qt developers have found additional things they can do by having the "moc" tool integrated into their build processes, and thus have expanded its scope.
But even if a day comes that Qt can totally get rid of "moc" in theory, in actuality there will still be a lot of people who actually need to use C++ compilers that still haven't implemented whatever new version of the standard accomplishes this.
Have there been progress with this?
Also, FWIW, moc-ng is based on libclang, which looks to be vaguely in the general direction of what you're getting at: https://woboq.com/blog/moc-with-clang.html
Such as? I have developed Qt applications for many years and never noticed downsides of the moc approach.