9 ms·
Giving up on wlroots-rs (2019)
- shmerl 6y agoWhat if wlroots was written in Rust, could it make it easier?
- pzone 6y agoYes, the post mentions a project called Smithay which is essentially this.
- _ikke_ 6y agoPrevious discussions: https://news.ycombinator.com/item?id=19778738 https://news.ycombinator.com/item?id=19778738 (2019)
- ironmagma 6y ago> However, the entire point of Rust is that it’s safe. It’s really not. That is a fringe benefit; there are a dozen other reasons to use Rust over, say, C++. The syntax is cleaner, there are async await semantics, locking is way better, destructors aren’t a dumpster fire, macros aren’t the wild west, there just isn’t as much cruft... and et cetera.
- pjmlp 6y agoJust wait until Rust manages to be used by all major industry players for 40 years and counting. So they finally sorted out the remaining issues with Drop traits and everything macro related works on stable?
- nine_k 6y agoI remember what C++ looked like in 1990s. No, the roots, the general unkempt hacked-together style had started by then already :( it's the efforts of last decade or so which made a relatively reasonable language out of C++. It wasn't corrupted by the industry, but it did corrupt the industry to some extent.
- pjmlp 6y agoMe too, a systems language that allowed me to avoid C as much as possible since 1993, already primitive versus the feature list of Turbo Pascal 6.0.
- burntsushi 6y agoRight, just like Rust is a system language that allows me to avoid C and C++ as much as possible since about 2015. There are very few other languages I could have realistically used for several of my projects.
- pjmlp 6y agoSadly I cannot say the same about Rust in what concerns my work domains, as explained at "Have you stopped using Rust? And if yes, why?" discussion thread on Reddit. C++ helped me avoid C, because I could drop down to the C subset when obliged to do so, and still take advantage of C++'s improved type safety, just validating at the end that a C compiler would also be happy with the code, and thanks to its Bell Labs heritage it has always been a first class language across all major UNIX/POSIX platforms.
- burntsushi 6y ago> Sadly I cannot say the same about Rust I know. It's hard to miss. :P My point was to reflect your claim of the suitability of C++. Rust is still young. Much younger in some domains than others. GUI is obviously one of them, and I suspect it will be quite a while before it ever catches up, if at all. If that were my requirement to use Rust, then I'd forget about it and check back in five years. I'm not sure where you are on the innovation curve[1], but I'd say Rust and GUI are all the way to the left right now. (I don't think Rust itself is, but GUI in Rust is.) There are bindings to existing toolkits, but as you say, they're hard to use. So I think some innovation is required and people are working on it. My guess is that you're somewhere in the "late majority" group on that curve. Partially because you seem to require support by the platform itself (not just platform support by the language) and also due to requiring a mature solution to a deeply complex problem (GUI). Those things tend to take a really long time to happen, if at all, unless they are built and created by the platform itself. Your desire for binary libraries isn't as out of reach though I think. It's just a hard problem to solve and there just honestly isn't a ton of motivation to do it as far as I can tell. It might require a well funded player to help move that along. (Not just in the work required to do it, but in the resources required to provide it I think.) [1] - https://www.ou.edu/deptcomm/dodjcc/groups/99A2/theories.htm https://www.ou.edu/deptcomm/dodjcc/groups/99A2/theories.htm
- cube2222 6y agoCould you please expand how destructors in C++ are a dumpster fire? (just curious)
- iso8859-1 6y agoRead this article and tell me it all makes sense to you: https://eli.thegreenplace.net/2015/c-deleting-destructors-and-virtual-operator-delete/ https://eli.thegreenplace.net/2015/c-deleting-destructors-an...
- jcelerier 6y agoHow else would you implement class-level customisation of dynamic allocation / deallocation ?
- Thorrez 6y agoCustom deletion operators are a much much more advanced topic than destructors. Destructors are a basic essential topic all c++ programmers need to know. The vast majority of c++ programmers don't need to know that custom deletion operators even exist.
- qalmakka 6y agoOverloaded delete operators are a relic of a past where malloc() was crummy and inefficient, and almost every object was allocated using new. Quoting Stroustrup: Introducing operator new thus made the use of free store more convenient and less error−prone. This increased its use even further so that the C free store allocation routine malloc() used to implement new became the most common performance bottleneck in real systems. This was no real surprise either; the only problem was what to do about it. Having real programs spend 50% or more of their time in malloc() wasn’t acceptable.I found per− class allocators and deallocators very effective. The fundamental idea is that free store memory usage is dominated by the allocation and deallocation of lots of small objects from very few classes. Take over the allocation of those objects in a separate allocator and you can save both time and space for those objects and also reduce the amount of fragmentation of the general free store. I think almost no one needs custom new and delete today, not only because they are very clunky and obscure, but especially due to the fact that modern C++ features such as move semantics, allocators, std::optional<> and NRVO make them almost redundant and unnecessary.
- tomjakubowski 6y agoExtensive pattern matching syntax and built in sum types are the only reasons I need to almost always choose Rust over C++. The rest is all bonus!
- pjmlp 6y agoThen have a look at what C++23 might bring, http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1371r2.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p137...
- lights0123 6y agoFinally. > 7.7 Matchers and Extractors: Other Languages Hmm... that "Other Language" looks quite familiar. And still no sum types.
- pjmlp 6y agoDepends on how you look at it, https://www.ida.liu.se/~TDDD38/lecture/slides/sum_types.pdf https://www.ida.liu.se/~TDDD38/lecture/slides/sum_types.pdf
- dimitrios1 6y agoThis just further proves the dumpster fire point made by others here. C++ is a kitchen sink language. It just has gradually become every and any paradigm. It no longer has any true identity, and I can't imagine that any new dev coming into the language has much of a shot of being successful. I do wonder how they are able to pull it off. It is truly remarkable in some way that they are able to have so many language features without it being detrimental to the language.
- pjmlp 6y agoSame applies to any other programming language of the same age. Or do you think that Fortran 2018, C17, C# 9, Java 15, Python 3.9, COBOL 2014, Ada 2014,... are any different?
- chrismorgan 6y ago> and et cetera. FYI, the “et” means “and”. https://en.wikipedia.org/wiki/Et_cetera https://en.wikipedia.org/wiki/Et_cetera is good reading.
- greggyb 6y agoAnd the 'cetera' means essentially 'the rest'. Though it is common in modern usage to to use 'et cetera' to imply a continued list of items not named. A stricter interpretation would only use 'et cetera' to refer to the rest of a full list that has been previously explicitly enumerated earlier in the text. As an example: The authors of the text were James, Malik, Susan, Srini, and Ying. ... <some more text goes here> ... This was the primary finding supported by Srini, James, etc. Above, the usage of 'etc' is to shorten the sentence, by avoiding a second instance of the full list. A simple translation to English shows that the common usage can leave much up to the interpretation of the reader. As an example: I like sweet foods: cherries, apples, grapes, and the rest. So, do I actually mean fruits? Do I mean all other sweet foods that exist? This sentence leaves a lot of interpretation to the reader, and depends on shared context to have any useful meaning. This usage of 'et cetera' generally means "and more in a sequence made up of items categorically in line with what I've named, which I assume, you, the reader, can infer." This reply is not meant to critique modern usage. Language is a fluid thing, and the use delineating implication, rather than eliding a fully enumerated list, is perfectly acceptable in the vernacular. I just wanted to share some additional nuance regarding the phrase.
- chrismorgan 6y agoIn your authors example, etc. is not what is conventionally employed, but rather et al. (https://en.wiktionary.org/wiki/et_al%2E https://en.wiktionary.org/wiki/et_al%2E, https://en.wikipedia.org/wiki/List_of_Latin_phrases_(E)#et_alii https://en.wikipedia.org/wiki/List_of_Latin_phrases_(E)#et_a...). This is an extremely strong convention. Increasingly I’d say I observe et al. being used for (a) lists of people, and (b) finite, known lists; and etc. being used for lists of unknown length. (You may notice there is some unspecified area in that classification. This is deliberate.) This is a definite shift from the original Latin.
- zelly 6y ago> there are async await semantics There are coroutines in C++20 now. It has the async/await syntax except it's extensible to any kind of coroutine semantics, not just Futures like in Rust. > locking is way better RAII was inspired by C++. For making a mutex own its associated data, that's a simple template class which is a well-known pattern. You're also not forced to use it when it is not a good fit. > The syntax is cleaner You got me, I have been trolled.
- ironmagma 6y ago> It has the async/await syntax except it's extensible to any kind of coroutine semantics Interesting, I didn't know about this. > You're also not forced to use it when it is not a good fit. But like all language criticisms that contain this sentence, it's better when the language makes it somewhat tedious to go outside of the norm, where the norm is defined as the 99% use case. C++ is the opposite; you have to go out of your way to use the generic, safe features like smart pointers or create copy constructors. Rust's syntax takes cues from ML which means that things like switch statements (matches), if's, and even return are also expressions, which makes it nicer to refactor and allows you more choices when structuring your code.
- lmm 6y ago> To avoid this callback hell, I defined two macros to help: one normal macro and a very complicated procedural macro. Here’s what the procedural macro looks like: > This expands out the lines to use the non-proc macro, which in turn becomes the callback hell mess. The only problem with this scheme is now that the control flow is all wrong: My instinct is that any sufficiently large project is going to hit a problem like this as soon as they try to do something the Rust devs didn't anticipate, unless and until the Rust people get monads working.
- nine_k 6y agoDo monads need language-level support? I suppose you can make your own quite well. Support in stdlib is another question, but can't e.g. Option and Result be used monadically with little effort? Am I missing something critical?
- lmm 6y agoYou can implement monads yourself if you have higher-kinded types, but Rust doesn't. Without them you can't implement any of the standard helper functions that you need generically (e.g. monadic versions of control flow functions like ifM, whileM), you'd have to implement them by hand for each different monadic type instead. Thus the control flow problems in the #[dehandle]-based code. And if you look at what #[dehandle] is doing, it's blatantly an ad-hoc implementation of do notation for these handle types. It's doing the same thing as async/await, or try!, but in (present-day) Rust everyone implementing a new "context-like" type has to write their own "very complicated procedural macro" to implement a specific variant for that context-like type. (I don't think you necessarily need do notation to write maintainable monadic code - I'm a big fan of railway-oriented programming style i.e. (Kleisli) arrow composition. But of course you can't do that in Rust either, except by writing ad-hoc implementations of all the operators and helper functions for every different type you want to work with).
- imtringued 6y agoYou're right every monad requires its own ad hoc operators in Rust but Error is already "blessed" with the try! macro. I think the irony is that he traded an Error result for an Error-less "Handle" object which required him to write his own macros. The intention to make things better made things much worse. However, API usability itself is not the problem. Although it was just a small portion of the blog: "Custom Wayland protocols aren’t possible" actually showed the real roadblock. It means wlroots-rs has no reason to exist.
- pjmlp 6y agoIt is more interesting to actually read the follow up article, "Way Cooler Postmortem" http://way-cooler.org/blog/2020/01/09/way-cooler-post-mortem.html http://way-cooler.org/blog/2020/01/09/way-cooler-post-mortem...
- MrBuddyCasino 6y ago> This naive style implementation could work, however it would cause a lot of branching code. Would this have been a problem in practice I wonder, premature optimization and all.
- DougBTX 6y agoYeah, it’d be interesting to see the Rust code contrasted with correct C versions. How does the C code deal with a monitor being unplugged? I wonder if it could be shuffled around to amount to an early return with an Unplugged error.
- vbezhenar 6y agoIf I understood it correctly, monitor doesn't really go away in your event handler, so C code don't have to deal with that.
- cycloptic 6y agoIn C, you're supposed to listen for a "destroy" event on the output and then in the handler you would delete all your references to the object. I would be interested to know if any language has a way to statically analyze this, instead of using a monad.
- imtringued 6y agoRust has the try! macro or ? operator so people already thought about this problem a lot. Rolling your own monad wasn't the best idea.
- zelly 6y agoSomeone should make a Rust Graveyard website like the "other" graveyard website except this one is for people giving up on projects due to an unaesthetic and pedantic programming language.
- ducktective 6y agoWhich other website are you referring to?
- zelly 6y agohttps://killedbygoogle.com/ https://killedbygoogle.com/
- qalmakka 6y agoI write C and C++ for a living, and the reason I prefer Rust to them is definitely not memory safety, that's just a nice plus. I think that lots of C/C++ developers have never thought for long about how you end up having to care about the same things in C and C++ too. In C++, you have to think about exception safety, lifetimes and move semantics when you write your code; you have to know if a variable is moveable, if it is worth it to do so, when and by whom it will be destroyed, etc. If you start writing modern and sane C++, you just realise that lots of the patterns you find yourself using are all things Rust already does automatically enforces for you at the language level. Meanwhile, often people forget that while C just does not care about what you do with memory, you still _must_ remember that objects still have lifetimes, memory still has ownership; the main difference is that the compiler neither enforces nor checks what you're doing with it. Just like in Rust and C++ you must know if a certain resource is yours or not, and you need to be actively aware of it and manage it properly by clearly documenting how it should be managed and where you expect it to change ownership. I cannot count how many times I saw C libraries forcing you to use reference-counted objects on the heap just to get out of the messy they used pointers. That is, lots of people find that some of their code references random objects in unsound places without any regard about ownership, and then they get need to find a way around it; refcounting is often the easiest solution. And don't get me started about people managing objects like this: struct obj; struct obj* obj_new(); void obj_delete(struct obj*); that is, simply forcing you to use heap allocation using malloc() (rarely, the objects might come from a pool, but it's not that frequent) without considering that you're forcing people to allocate memory (and fragmenting the heap) for short-lived objects that could have well resided on the stack; it also makes a library unusable for those people who might want to use your library on a system that has no heap or has an heterogeneous memory model where not all memory is the same. I have seen a handful C libraries actually care about allocators, but they are definitely not the norm. This is also the reason why I started using C++ on embedded systems such as the ESP32, where flash is relatively abundant (it gets up to 16 MB in some configurations) but internal, on chip ram is still scarce for lots of advanced use cases (~512K) and you need to rely on SPI-connected RAM to actually get work done. C++ libraries that use allocators can be used on such systems without any issue, by simply writing your own allocator; Rust still has not such a nice allocator system in place, but at least it allows you to use the stack and return almost everything by value. In the end, my point of view is that switching from C or C++ to Rust should not feel like you're radically changing the way you code regarding ownership and memory management, because it's orthogonal to the language; it's something you that always needs to be a crucial point in the code you design. In my experience I learnt that 99% of the time when you feel that Rust is hindering your design it's because your design is either unsound or depends on trusting safety assumptions that are enforced outside of your program (i.e. the OS is guaranteeing this, or this is not physically possible). Rust will always guarantee safety as long as the postulates it lies on hold, but you should not expect it to make a potentially unsafe C library 100% sound because the language can only go as far ahead as ensuring the code you wrote in it is doing exactly what you've said it should do, and nothing more. Lots of C libraries are often based on an assumption of trust. They just assume that some things will always happen in a certain way, or that certain events are not likely o serious enough to justify wasting time on writing code to check them. This is, I think, the reason some things can't be directly model on top of Rust, because Rust has been made explicitly to force you to eliminate the occurrence of certain errors, so you either have to implement yourself boilerplate code to guarantee your library behaves like Rust wants it to behave, or you accept the need of writing unsafe code.
- _-___________-_ 6y agoWhy even give out (a reference to, ownership of) an object that represents an output, when the output might disappear at any time? You could instead have some output controller which encapsulates all the operations one can do with outputs, which can simply return Err(OutputNotFound) if you try to operate on an output that was disconnected between you learning that the output existed and you trying to do some operation on it.
- cycloptic 6y agoThis is covered in the article: >This naive style implementation could work, however it would cause a lot of branching code. Each call to wlroots will require a check to see if the handle has been dropped, even though it almost certainly has not been dropped (it can only be dropped between event callbacks, wlroots/Wayland is callback based). This means there will be unnecessary paths (that are hopefully marked cold) that either panic or return an error.
- baseballdork 6y agoWould this not be necessary in C? I've not written C since that one semester in college, so I'm having a hard time imagining how C handle this differently.
- cycloptic 6y agoIt depends. Copying my response from farther down in the thread: >In C, you're supposed to listen for a "destroy" event on the output and then in the handler you would delete all your references to the object. If this wasn't satisfactory for whatever reason, then you could implement it as a weak pointer and check for null every time, but you wouldn't have to.
- _-___________-_ 6y agoI'm going to go out on a limb and assume that they did not build a small proof-of-concept and do some benchmarking to see if those unnecessary branches actually result in any meaningful performance issue in the context of a Wayland compositor.
- phibz 6y agoCouldn't you create a "system" or other object and have it own the displays by encapsulation. Then ask it for a display when you need it. If the display exists for the duration of a callback then I would think simply passing the display as a borrowed reference to the callback would enough. And if you're gonna use C why not just use unsafe rust?