Threads for BenjaminRi

  1. 2

    Careful with GCC 11. They made a change in C++, they are more strict about #includes of headers [1]. Expect a lot of existing code to break. I actually had to downgrade to get very large projects to build again.

    [1]: https://gcc.gnu.org/gcc-11/porting_to.html#header-dep-changes

    1. 2

      They made a change in C++, they are more strict about #includes of headers.

      What they did is stop including headers they don’t need. Code that relied on such (non-portable, I must add) side-effects was always broken and now has to be fixed.

      1. 1

        Linus Torvalds would reply: “We do not break user space!” If a Linux API works one way for 20 years, and everyone relies on it, you don’t just break everyone’s code. Why is GCC/C++ different?

        Why is code that compiled and worked perfectly well for 20 years broken? Perhaps it is broken by some definition, but it begs the question if the standard is broken and the code is correct. About your comment that the code is non-portable, I already wrote a lengthy blog post about this subject: https://mental-reverb.com/blog.php?id=24

      2. 1

        Could they not have added a warning for a couple of versions before implementing this? It seems like one of those things that should be easy for a compiler to check for, and automatically fix or warn. Like “hey, you gotta add #include since you’re using it, and not depend on another standard library header to include it for you…”

        1. 1

          Sounds like a nightmare of special cases tbh. It’s the same definition, so you have to keep track of the whole chain of includes. Actually multiple chains and their ordering, because you could first include the class through the side-effect and then explicitly. And then you have things created through defines. And you have to keep the list of the cases to warn about.. :scream:

          I think that’s one of those things that seems simple to do, but isn’t :-( gcc keeps only the first place something was defined if I remember correctly.

          1. 1

            It’s a simpler problem than that because it’s a standard library with a set of well-defined symbols and you need to handle the case where these identifiers are used but are not defined. You can maintain a list of function and type names and the headers that the standard says they come from and tell people what header they’re missing. Clang does this for a load of C standard functions.

        2. 1

          To be explicit, this is not a change with GCC, it is a change with libstdc++ and will affect any compiler using the same implementation. Historically, libstdc++ has always had a policy of minimising header includes, which is why code written against libc++ (which doesn’t) often fails to compile. The fix is always trivial: add the headers that the standard says you need to include. With modules (any decade now), all of this will go away and I can just put import std; in my C++ source files if I want to use the stdlib.

          This is a far less annoying bug than the one in 20.04’s GCC 9.4, where the preprocessor evaluates __has_include(<sys/futex.h>) to false, in spite of the fact that #include <sys/futex.h> works fine. This has no simple work around and is why I’ve given up supporting GCC 9.4 on Ubuntu for some projects: GCC 10, 11, or any version fo clang is fine. Apparently the bug is something to do with the weird fixincludes thing that GCC does, meaning that the search paths for #include and __has_include diverge and so __has_include is not reliable.

        1. 33

          A title describing the same problem from a different angle would be “The mess we’ve gotten ourselves into with single-page-applications

          1. 6

            How about “The proliferation of JavaScript and our failure to prevent servers from acquiring vast stockpiles of such code

            1. 4

              Can you elaborate? Classic SPAs don’t have this problem because all their functions are “client colored” (to borrow the terminology of the post).

              1. 7

                I guess the answer is that Classic SPAs are good until you need some SEO which is probably very common. Hence SSR. Although technically speaking SPA per se don’t need SSR (maybe for performance but shouldn’t be an issue if things were developped correctly by default I’d say).

                1. 15

                  I was thinking the same thing. The title could easily be “The mess spawned by organizing the web economy around a search monopoly”.

                  1. 9

                    IMO, this is the wrong intuition. Categorically, pages that need to be SEO-opitimized are those that are informational. You don’t need SEO for a desktop app, nor would you need that a web app because a web app is the same thing but distributed through the browser (but sandboxed, not making users require a download executables, and on a highly portable platform available on almost every OS and architecture). These two concepts are not the same thing despite both being delivered through the browser; you shouldn’t use a SPAs tech stack for a basic page because information category pages don’t require the same shared state management and usage of device feature APIs that an application might. I can use Wikipedia from a TUI browser because it’s 95% information. It was the exact same issue in the Flash days of not using the right tech and society has permanently lost some content from its internet archive.

                    So it’s not “when you need SEO”, but SEO should be a requirement from the get-go in helping you choose a static site or dynamic, multipage application where the server always did the rendering.

                    The problem is the tooling. The NPM community instead of having an intuition about the right tool for the job and stating “do not use this tool for your static content”, we have tools that try to solve everything and hide the mountains of complexity that should have scared devs away from the complex solution into the simple one. It should be hard to make a complex pipeline like that of server-side rendering for a SPA. And that easy tooling is riddled with bugs, megabytes of node_modules, and might invite you to start involving more complexity with tech such as ‘cloud workers’, but people don’t find out until they are way too deep in the Kool-Aid. Many don’t seem to see this issue because influencers are pushing this stuff to get GitHub stars and have, ironically, gotten all of the top ranks when searching for a solution (or people were asking the wrong questions without knowing).

                  2. 3

                    Not the poster you’re responding to but it might be because SSR is a fairly natural leap from SPA-style apps. They might also be implying that it’s my fault, which would be nice, but unfortunately isn’t the case.

                1. 22

                  I disagree with this take. I believe that the software freedom movement needs a diverse spectrum of proponents with differing determination to enforce freedoms. We need absolutists like Richard Stallman and we need convenient but somewhat compromised distros like Ubuntu. Ultimately, if everyone thinks that Richard Stallman goes too far and uses Ubuntu instead, then GNU/Linux has almost entirely taken over, so it’s a win for the software freedom movement after all. The GNU philosophy shifts the overton window radically into the direction of software freedom, and even though their viewpoint may be extreme to some, this makes the Ubuntu user a moderate, which is a good thing. Remember: You are all on the same side, it’s just the extent of the goal that differs. After all, you would use fully open hardware and software over the proprietary stuff if it was just as affordable, reliable and available. Your problem is not the GNU philosophy, your problem is that the proprietary stuff is simply too desirable, so you compromise on your morals to get the technology you need. There’s nothing wrong with that, but don’t blame GNU for it.

                  1. 14

                    I’d say the core problem is that the FSF (and by extension the GNU project) suck all the air out of the room while being solidly stuck in the past. They’ve completely ignored the reality of the modern age with companies like Amazon existing as they do. Sure it’s truly “free” to release something under the GPL then have Amazon take it, make some small changes, then host it. They’re allowed to under the GPL as they should be, but that seems like it goes against the principles of the FSF, GNU, and the GPL. The AGPL isn’t air tight, it’s sure as hell better than most other licenses and I personally use it, but we need better. We need a group focusing on the issues of the modern age.

                    We need a group who are focusing on the current issues with hardware and software freedom. Proprietary SaaS services and modern hardware. It’s all fine and good making sure your shell, editor, and kernel are truly free. But if they can’t run on hardware most users can actually get or need what’s the point? Most users can’t or aren’t willing to use an almost 15 year old Thinkpad as their one and only machine. Most users can’t run Replicant, they need access to Google Play Services and proprietary apps to actually live their life.

                    We need a group providing aid and resources to tackle these problems. Tools, training, equipment, and materials to help reverse engineer hardware and software. Very few people have the knowledge, ability, and free time to reverse engineer modern hardware, what if we had more? How many fewer binary blobs and proprietary drivers would we need if we actually focused on getting rid of the need for them rather than trying to pretend we don’t need them? Wouldn’t it be great if we had licenses for modern problems like cloud providers modifying, extending, and hosting services without providing the source.

                    Absolutism has it’s place, that’s for sure, but how do we actually get to that absolutist’s position? It requires work that the FSF and GNU just aren’t focusing on. And they hold their position while trying to be seen as the one true group who can deliver us to that position. Maybe another group needs to come along and actually do the work, but it’s hard with the FSF/GNU in the room.

                    1. 6

                      Broadly agree, but a couple sticking points:

                      They’ve completely ignored the reality of the modern age with companies like Amazon existing as they do.

                      Would Amazon (and other _aaS providers) be the behemoths they are today if people had stuck with GNU/FSF principles? Would there be such a great demand for their services if new developers had been brought up in a culture where you were both expected to know and have access to the internal of your software and share your work?

                      And they hold their position while trying to be seen as the one true group who can deliver us to that position.

                      That is rather the advantage of taking an uncompromising absolutist stance…by stubborn refusal to compromise it is much easier to make the claim that they are the one true group and that their approach optimizes for their ideology and minimizes change of corruption. The last…six?…years have shown that the slippery slope fallacy seldom is.

                      1. 3

                        We need a group who are focusing on the current issues with hardware and software freedom. Proprietary SaaS …

                        We need a group providing aid and resources to tackle these problems. Tools, training, equipment, and materials to help reverse engineer hardware and software. Very few people have the knowledge, ability, and free time to reverse engineer modern hardware, what if we had more?

                        This analysis is a bit wishful in that it totally ignores economics (the root problem). Let’s say we had a group such as you describe, where are the incentives? where is the funding? why won’t this “pure” group immediately get outpaced by the group that forms around it to exploit the contradiction between the current economic system and the fiction you propose. The latter group would likely become relatively big quickly (size depending on the competence of the former group).

                        I think we need a new economic system. We measure the wrong things and as a result we compete to make the wrong numbers go up. Who cares about the exact score of a passing grade? or how many jurors were unsure in a “not guilty” verdict? consider the phrase “fuck you money”, what does it mean? … From what I can tell; we would not have a (a priori) global (reserve) currency in a truly decentralized system, there cannot be a central coordinator, so we cannot have a (postulated) global currency. At best it’ll be emergent from the reputation system we end up with.

                        What I worry about is that the software that gets built is the software that gets used. All the FOSS world lending a helping hand with better contact tracing software (instead of communication software, which is just as needed in a pandemic that may go on for an indeterminate amound of time) is a symptom of this problem. We need to be smarter about our priorities or we will end up running our governments and “citizen points” (a.k.a. “how to wealth distribute” from pov of gov) on some chinese system “because it exists” … please let’s not have that happen.

                    1. 7

                      In the same vein, the Linux kernel is not written in C. It immediately becomes apparent when you read and write kernel code. This has many reasons, for example that Linus Torvalds thinks that the ISO C Standard is a “piece of garbage” that imposes “braindamage” which needs to be undone [1] and also because the kernel uses non-standard GNU C extensions [2]. Think of that what you will, I guess it works well enough to power most devices on the planet. Makes you wonder if the Linux way of writing C should be the actual C standard.

                      [1] https://lkml.org/lkml/2018/6/5/769

                      [2] https://www.kernel.org/doc/htmldocs/kernel-hacking/conventions-gnu-extns.html

                      1. 11

                        I think that’s somewhat different. Rails is using Ruby to implement an embedded DSL that is quite Ruby-like. Linus is using a language that is mostly the same as C, ignoring what the standard says, and then complaining that security vulnerabilities in his kernel are someone else’s fault when they arise from the compiler implementing the standard.

                      1. 9

                        This is totally a nitpick, but “Rust has a really solid base of users now, in terms of number of users, diversity of domains, committent of users, size of users, etc” made me wonder if they’re happy about having more large people writing rust. Tall people? Heavy people? Maybe I’m getting the direction wrong, maybe small people? What size of user do we have now, and why is this size better than last year’s?

                        🤡😆

                        1. 3

                          It took me a moment, but they probably mean e.g. large organisations vs small ones.

                          1. 2

                            Maybe we should be more gluttonous to put more weight behind the Rust ecosystem ;-)

                            1. 1

                              I’m always ready to be more gluttonous.

                          1. 9

                            He raises the dynamic allocation problem of exceptions, but I have another problem with exceptions that I don’t really see treated a lot: Complete interface obfuscation. Suppose you include a library header. Suppose that library allows you to call void foo();. Can that function fail? If so, what exceptions does it fail with, under what circumstances? If you’re lucky, the documentation is good. Often, the documentation doesn’t even exhaustively list possible exceptions. Often, I have to look through the code and search for throw statements. As far as I know, there isn’t even good tooling to run over a code base to find out what exceptions a function may throw (please tell me if you know one). How is that ever acceptable? I want to know how and why my API calls can fail.

                            Contrast this with the Rust approach. We immediately see: fn foo() cannot return any errors* and fn foo() -> Result<T, E> will either give me a T on success, or an error description E on failure. If that mechanism makes error handling harder, that’s just because with exceptions, you didn’t even really handle them. I’ve actually worked on numerous C++ projects where the exception madness caused very real problems. Ever since, I completely stopped using them and started wrapping libraries that use them such that exceptions are turned into error codes. This also forces me to find out how the API calls can fail.

                            * Okay, there’s still the panic mechanism, but this is only for rare and very severe errors. Avoid it whenever possible.

                            1. 10

                              there’s still the panic mechanism, but this is only for rare and very severe errors

                              Panic in Rust is for signaling that a bug in the program has been detected. It is not appropriate for expected failure modes in a correct program. For rare or very severe, abort would be better.

                              1. 6

                                This is the checked vs unchecked exception choice. C++ tried to support both for a while, for example:

                                void doesNotThrow() throw();
                                void throwsForOrBar() throw(Foo, Bar);
                                void mightThrowAnything();
                                

                                There are a few problems with this approach. The first is that adding a new error result changes the signature of a function. This is not specific to C++ but it generally means that you rely on subtype relationships to extend the set of things a function can return. In the worst case in Java you get things that can throw Exception - great, it will throw some subclass of a generic exception class and I’m expected to down-cast it to the right thing once I get it and figure out what to do with it. Thanks. Oh, and this was worse in C++ because exception specifiers were not part of the type system so you could store all of the above in a void(*)() variable and have absolutely no idea what exceptions would be thrown.

                                The second problem is that C++ decided to dynamically enforce these things. This meant that your unwind logic had to check exception specs on the way up the stack and a function with throw() would get unwind tables generated to guarantee that exceptions didn’t propagate through it (and would call std::unexpected in these cases). This was very painful for the unwinder and for binary size.

                                C++17 removed exception specifiers and made noexcept part of the type system. This means at least that you know whether exceptions can or can’t be thrown but you still rely on documentation to know which exceptions might be thrown.

                                1. 1

                                  Suppose that library allows you to call void foo();. Can that function fail?

                                  The noexcept keyword helps with that, but the library implementor has to add it. And there’s no static checking that I know of to verify that a noexcept function’s implementation doesn’t fail to catch any exceptions (in which case the program will abort rather than allow the exception to propagate.)

                                  My opinion is that in C++, exceptions are deeply problematic, but better than current alternatives. Error codes are toxic for good API design and don’t work with constructors or operators. There are some decent library implementations of Rust/Swift/etc. Result types, but I haven’t tried using them in any serious codebase yet.

                                  I’ve seen a C++ WG proposal for overhauled exception handling that works very much like Swift under the hood, and it looks great, but I don’t know if that’s going into C++23.

                                1. 4

                                  Does your blog have an RSS feed? Quite the fun read!

                                  1. 5

                                    Thanks! Unfortunately, it does not. It’s just a pile of simple PHP I wrote some time ago. I should implement it, I got that question a few times already.

                                    1. 4

                                      Also the “statistics” at the bottom, and the theme switcher! ❤️

                                    1. 3

                                      This is nice advice for a novice programmer. However, as a seasoned programmer, you start finding these bugs all over the place. Bugs in libraries, in the compiler, in distro binaries, in the operating system, even in the CPU. Of course, stay honest and humble. Debug your own code first. Extraordinary claims require extraordinary evidence. But never assume that the foundation upon which you build is perfect.

                                      This year, I found a bug in the ps binary distributed by BlackBerry QNX. That took a while to find and understand. You can read my write-up here, hopefully you are entertained: https://mental-reverb.com/blog.php?id=29

                                      1. 8

                                        An interesting dynamic I’ve observed as an embedded software engineer is that all developers are expected to understand the parts of the stack above them. So, the hardware designer is expected to also know firmware and software development. The firmware developer is expected to know software development. But don’t ever expect a software developer to know what a translation lookaside buffer is or how to reflash the board. In addition to that, if the bottom of the stack (e.g. the hardware) is broken, it’s impossible to do solid work on top of it. This is why talent and skill migrates towards the bottom of the stack, because that needs to be done right for everything else to even have a chance of working.

                                        1. 3

                                          In my own experience firmware/hardware/ee development is very fluid. FW development frequently bleeds into EE/HW development, and the same is true for the other two. It’s almost a necessary thing: the complete machine is one, and wouldn’t work without the sum of these.

                                          But it’s true there’s generally a tipping point above the OS level where knowing the lower-level details has almost zero impact on the stuff you’re writing, especially with modern CPU speeds. Is it bad? IMHO good engineers are always aware of the stack above and below them.

                                          If I’m writing JS, my lower-level stack would be equally vast and complex: browser, protocols and latencies involved, network infrastructure, caching, dns… I’m not convinced embedded dev is “harder” by itself.

                                          The difference is that maybe I’ve seen many more clueless JS devs than FW devs, but latter exists too.

                                          1. 1

                                            I’m not convinced embedded dev is “harder” by itself.

                                            Agreed. I’d say that it’s mostly a case of embedded being different. And since a lot more people work with and write about higher level code, it’s not surprising that there’s more and better help, documentation and tools available there, which makes it easier to learn that stuff even if the subject matter isn’t inherently easier.

                                        1. 35

                                          TL;DR: They stopped sending reverse deltas for rollback and now generate them on-the-fly during installation.

                                          1. 16

                                            They gotta be kidding, right?

                                            We discovered that these transforms and patches can be “observed” by the delta apply step

                                            “DISCOVERED”. No shit Sherlock! Also, easy to miss icing on the cake at the end of the article:

                                            [1] The approach described above was filed on 03/12/2021 as U.S. Provisional Patent Application No. 63/160,284 “REVERSE UPDATE DATA GENERATION”

                                            1. 7

                                              You clearly haven’t worked at a BigCorp or you’d know they force you to patent anything no matter how trivial. I have several such patents to my name, which I would be embarrassed to link to (the patent plaques I got went straight into the trash). All the nontrivial ideas I’ve had (some of which have shown up in research papers) have never been patented, to the best of my knowledge.

                                              1. 3

                                                There is no pressure to patent things at Microsoft.

                                                1. 1

                                                  I wasn’t pressured, I was just told “sign on the dotted line”. Ditto at Amazon. I’m sure things are no different at GOOG or FB. Big companies are forced to maintain an arsenal of defensive patents for strategic reasons, so I can’t blame them for responding to incentives.

                                                2. 2

                                                  Can you just put references to the prior art in the patent application and save the examiner some time?

                                                  1. 2

                                                    Yep. An old colleague of mine has a patent for “generating a receipt after a transaction, but not showing the receipt to anyone at the time just storing it somewhere where it’ll get aggregated into a big receipt database” or something to that effect.

                                                  2. 6

                                                    That reminds me of those patch notes when after more than two decades, the Internet Explorer engineers discovered that the DOM can be stored in memory as a tree instead of a long string that contains all the elements [1]. Kind of a “car mechanic discovers the concept of a wheel” moment. The fact that this was a noteworthy thing a few years ago blew my mind. No wonder Internet Explorer was left in the dust by its competitors.

                                                    [1] https://blogs.windows.com/msedgedev/2017/04/19/modernizing-dom-tree-microsoft-edge/

                                                    1. 7

                                                      Using a string data structure (a highly optimized one mind you) for the DOM wasn’t a stupid decision at all back when the DOM really was “just text” and programmatic DOM manipulation wasn’t really a thing.

                                                      1. 1

                                                        Very true, though IE sucked at it even then. :-P

                                                  3. 3

                                                    That’s surprisingly sensible! You can probably generate the rollback delta as you apply the forward patch.

                                                  1. 1

                                                    A skilled programmer is a skilled linguist. Period.

                                                    1. 3

                                                      I believe that the thing called “computer science” does have its place and has the correct name. Language theory like the Chomsky grammars [1], research about computational complexity [2] and algorithm design are actually quite pure sciences that have more to do with mathematics than with programming or engineering in general. You can make significant contributions in these fields with pen and paper, no computer needed. Of course, few people actually work at this level. Your local coding bootcamp has little to do with computer science because it focuses on applied contemporary technology. Either way, science and engineering are married together, one example of that is troubleshooting a difficult bug which is a process that requires the application of the scientific method and is conceptually identical to figuring out complex processes in nature.

                                                      [1] https://en.wikipedia.org/wiki/Chomsky_hierarchy

                                                      [2] https://en.wikipedia.org/wiki/Computational_complexity

                                                      1. 3

                                                        “Computer science” is a melange of disciplines with little in common, which fall under the same rubric for purely historical reasons. Complexity theory or formal algorithms logically belongs in the mathematics department, while systems or software engineering research logically belongs in…well, engineering.

                                                        1. 2

                                                          Agreed – I’ve long felt that the field called “Computer Science” largely consists of the weird leftover odds and ends that fell off the trucks of other fields. Much of it is engineering and math, but there are also bits of psychology (HCI), biology (bioinformatics), statistics (ML/AI), etc.

                                                      1. 8

                                                        Does anyone else have the problem that Matrix is incredibly slow? I have a top of the line desktop PC and it takes 20-60 seconds from double clicking the icon until the Element client finishes with all the spinners and freezing and becomes usable. Also, how can I extract conversations in a usable format (e.g. SQLite)? These are my two biggest pain points with Matrix and the reason why I don’t use it.

                                                        1. 9

                                                          You’re describing problems with Element, which is fair. It’s an electron app, and it’s memory hungry. So is Signal.

                                                          The difference is that you can use Matrix without using Element; there are 3rd-party clients out there that work great with much better performance footprints. If you don’t want to use the Signal electron app, or if Signal decides your platform isn’t worth supporting (like arm64) then your only option is to not use Signal.

                                                          1. 8

                                                            If Element is showing spinners for tens of seconds, that’s all time spent waiting for the server to respond.

                                                            Synapse is (at least was) slow. Back when I’ve tried running it, there even was a postgres query you had to run occasionally to clean up things that brought it to a complete halt. Thankfully it seems that Conduit is a server project that will actually be good.

                                                            1. 2

                                                              The server stack isn’t much better performance wise, sadly.

                                                              1. 1

                                                                It’s an electron app, and it’s memory hungry. So is Signal.

                                                                Signal Desktop on my laptop has been running for a couple of days. It is using 23.1 MB of RAM (between 3 processes, two using about 1 MB) and is responsive. Restarting it takes a few seconds and it’s usable as soon as it presents the UI.

                                                                1. 3

                                                                  That experience is completely different from mine, but arguing about it is academic since I don’t even have the option of running it on my machine any more even if I wanted to.

                                                              2. 2

                                                                It seems fine as a Weechat plugin for me

                                                                1. 1

                                                                  Which server do you use? I run my own with (usually nearly) the latest versions of Synapse, and I don’t see any such problem. Starting up the client on my iPhone just now took 4 seconds, on my Linux laptop it took 12 seconds (but normally it’s always running and available as a panel icon).

                                                                  1. 3

                                                                    Same here. A friend of mine chats with me over the Matrix “default” home server and I’ve seen his client freeze like that too, while for me it’s always been fast (I’m using a self-hosted home server). I think there need to be more alternative servers and awareness of how to use such alternatives.

                                                                    1. 1

                                                                      Yeah, I think Matrix.org is slow, because they haven’t been able to scale in proportion to their users. Synapse is overly resource-hungry, but it’s not actually slow unless it’s starved of resources. Small homeservers are pretty much always faster than Matrix.org.

                                                                1. 7

                                                                  I wish they wrote more about ways to return values and report errors:

                                                                  • return errors (bool? error code? error object?)
                                                                  • out parameters
                                                                  • exceptions
                                                                  • return std::variant (or std::optional)
                                                                  • errno

                                                                  Bonus points if all these things clash in a single code base. Error design is super hard in C++. It’s much easier in Rust thanks to Result, but it’s still hard to get right in Rust!

                                                                  For example, one of our C++ guidelines is to only allow a single ‪return statement to exist in a function. A danger with having multiple ‪return statements is that adding new ‪return statements to an existing function can potentially miss a required piece of logic that was setup further down in the function.

                                                                  I believe that this rule is misguided. I much prefer the opposite: All resources are managed by RAII. Cleanup jobs are managed in the destructor of local objects on the stack (you can also create your own defer call with a few lines of C++). Write your code such that you can return or throw exceptions whenever you like and everything is cleaned up automatically, as it should be. The reliability of code written like this is amazing and it’s very easy to read, much easier than if every function is always traversed all the way to the end. This reduces cognitive load. My functions are riddled with return statements and have a huge cyclomatic complexity, but they are very easy to understand and modify. You can add a throw or return statement wherever you like and nothing breaks.

                                                                  1. 2

                                                                    Resources in C++ are usually managed by RAII, they’re probably referring to other state changes, such as message broadcasts, etc. which often occur conditionally in game code. I’m amazed they don’t allow an exception for guard clauses.

                                                                    1. 1

                                                                      It doesn’t matter if it’s a resource or a necessary state change that has to happen before returning. You wrap it in the destructor of a local object on the stack (defer it) to make sure it’s always executed no matter how you leave the function.

                                                                    2. 1

                                                                      Single return also was a standout for me, but I wasnt sure if it was a result of me not using C++. Thanks for making remarks about this!

                                                                    1. 4

                                                                      It hurts me to see how much C++ neglects the problem of compile time reflection, even though it’s absolutely crucial in:

                                                                      • Entity component systems (ECS), e.g. for video games and 3D engines
                                                                      • Marshalling/unmarshalling of data packets
                                                                      • Serialization/deserialization of JSON, XML, etc.
                                                                      • Storing and loading objects to and from databases
                                                                      • Printing or dumping object contents, e.g. for debugging purposes

                                                                      And every nontrivial application will grow to do at least one of these things. It’s just such a pain… I ended up writing a set of C++98 (I need to support ancient compilers) compliant macros that are minimally obscure and give me a powerful reflection API. You have to wrap the class/struct member declarations into a macro but it’s rather painless. Since then I haven’t used anything else. But since I’ve learned Rust, the ugly kludges that are required all day every day to implement ordinary C++ applications give me headaches and I started pivoting away from C++ wherever possible.

                                                                      1. 3

                                                                        C++ hasn’t neglected compile-time reflection, it’s just really hard to get right and once you’ve defined the interfaces for it then you’re stuck with them basically forever. It’s likely to be part of C++23, the reflection TS has been gradually approaching convergence for the last few years.

                                                                        1. 1

                                                                          The first C++ standard was released in 1998. We now speculate that compile time reflection will be part of the standard in 2023. That’s a quarter century later than it should have been made part of the language. During this time, the C++ committee introduced a myriad of less useful language features. Yes, that is neglect. Do you know how long it will take for this feature to be supported on embedded devices whose compilers notoriously lag behind? Maybe in 2030 or 2040 I will be able to use compile time reflection in a real product.

                                                                          1. 1

                                                                            Looking forward to it. I love the kind of stuff you can do in Zig — like writing a “for” loop over the fields of a struct. So intuitive!

                                                                            Are there any articles that describe the C++ reflection proposals in layman’s terms?

                                                                            1. 1

                                                                              There is 4 year-old article with title: ‘Reflections on C++ reflection proposals

                                                                              I like the title quite a bit :-)

                                                                          2. 1

                                                                            You have to wrap the class/struct member declarations into a macro

                                                                            Yep, I have been doing the same. I am thinking to do ‘an upgrade’ (for my ’09 code) to, now, use const expressions (although, I also like the approach proposed in [1] with CMake).

                                                                            I would also add to your list of critical ‘capabilities’ of a modern programming language, where reflection is needed – is the support of declarative and reactive GUI.

                                                                            Without reflection feature, every GUI library developer – brings their own reflection feature.

                                                                            Mature languages, like C++ need something like –error-on-undefined-behavior-features compile time switch, such that when used the compiler will error out on usage of library calls, idioms, language features that do not have a well defined standard behavior.

                                                                            This switch should also affect if a given precompiled ‘module’ can be used or not.

                                                                            This way, may be we could the language standard and its implementation to evolve a little faster. And the community usage around new features will grow faster.

                                                                            [1] https://onqtam.com/programming/2017-09-02-simple-cpp-reflection-with-cmake/

                                                                          1. 11

                                                                            The meat of this article is pretty good, unfortunately it is halfway down after reading through what anyone outside the movement could only see at an anti-government borderline-covid-denying rant. I honestly feel that, your personal feelings on how the pandemic should be handled notwithstanding, the point would be clearer and more forceful if given the main spotlight of the article.

                                                                            1. 11

                                                                              The meat of this article is pretty good, unfortunately it is halfway down after reading through what anyone outside the movement could only see at an anti-government borderline-covid-denying rant.

                                                                              That “Unfortunately” represents an extremely politicized opinion. There are lots of good reasons to be opposed to (your particular) government, including actions that (your particular) government has undertaken in the name of managing the coronavirus pandemic. Similarly it is reasonable to be suspicious of people using “borderline-covid-denying” as a way of dismissing an argument - “borderline covid-denying” implies that the OP did not in fact deny the existence of the covid pandemic, and there are lots of statements that are semantically close to denying the existence of the covid pandemic - like “it’s bad if the government forces people to install closed-source software on their cell phones in the name of fighting pandemics” that constitute extremely reasonable political arguments.

                                                                              1. 4

                                                                                Again, I did not dismiss the argument or (necessarily) even disagree with the rant. This was meant as constructive criticism of the article to say that focussing on the point/meat would make the point punch harder with all audiences.

                                                                              2. 8

                                                                                The opening section is a bit of a waffle; I have trimmed it down. The “papers, please” section in particular was true but off-topic. The techno-authoritarianism remark remains true, but is hard to elaborate in an on-topic way, so it’s been removed too. (Aside: Population-level vaccine targets provide aligned incentives without compromising people’s medical privacy or bodily autonomy.)

                                                                                It is possible to build privacy-preserving check-in, and to legislate protections for the data; it is a travesty that Australia has pretty much done neither. (Small exceptions: Western Australia legislated protections after it was revealed that the police accessed contact tracing and border pass data, and the federal government’s failed COVIDSafe app has strong legal protections also.)

                                                                                I think you are being extremely rude and uncharitable to lump me in with some “movement” of nutters, and I’d like you to apologise. Like most Australians, I am waiting patiently for our vaccine rollout to crawl down the age brackets, increasingly frustrated that additional restrictions and surveillance are imposed on citizens because of the government’s failures.

                                                                                (Quote of the removed original text below, for reference):

                                                                                Over the past year, there have been incredible restrictions on people’s freedoms of movement, speech, and association, in the name of protecting public health. On a recent trip, I was required to carry travel papers for 14 days, and to show them on request to certain classes of authorised officers — something I never thought I’d be required to do in a first-world liberal democracy.

                                                                                In Australia, we are now required by law to pump our personal information into one or more “contact-tracing” platforms in order to visit the supermarket or have something like a normal social life. This all-but-forces people to own a smartphone, and to interact with an enormous pile of proprietary software just to participate in society. Despite earlier promises to only be used for contact tracing, these databases have been used by police. Because of course they have.

                                                                                Elsewhere, there are talks of “vaccine passports” on smartphones, which accelerates techno-authoritarianism and should therefore be resisted. (Search for “raise the more generalized version of this objection”.)

                                                                                1. 9

                                                                                  I think you are being extremely rude and uncharitable to lump me in with some “movement” of nutters, and I’d like you to apologise. Like most Australians, I am waiting patiently for our vaccine rollout to crawl down the age brackets, increasingly frustrated that additional restrictions and surveillance are imposed on citizens because of the government’s failures.

                                                                                  1. He meant the Free Software Movement, the one you’re advocating in the piece.
                                                                                  2. That removed original text is pretty easily construed as an anti-government borderline-covid-denying rant.
                                                                                  1. 5

                                                                                    I disagree with your claim #1: as it’s embedded in the sentence “anyone outside the movement could only see at an anti-government borderline-covid-denying rant”, it reads pretty clearly to me like it applies to the various covid-is-a-conspiracy “movements”.

                                                                                    I can back everything in #2 with links to mainstream (i.e. not Murdoch/fringe/conspiracy-tier) news articles or to the relevant health orders, but to do so would take us further off-topic. I still do not understand this reading that you and singpolyma seem to see in the original text. (The “borderline-covid-denying” part, in particular. Whatever; it’s off-topic and removed from the main post, anyway.)

                                                                                    1. 5

                                                                                      If you have been paying even a modicum of attention to news, you know that there are and for a long time have been people who, no matter what crisis or emergency occurs, immediately denounce it as either a complete fiction or at best having been blown out of proportion as a cover story for the “truth”, which always is that the (insert preferred evil conspiratorial one-world-government entity here) wants an excuse to finally confiscate all our guns, terminate our freedoms, and institute worldwide dictatorship, all of which is only held at bay by badly-formatted postings from lone heroes on the internet.

                                                                                      What people are telling you is that the quoted section of your post sounds like one of those paranoid rants, in that it can be read to imply that contract tracing and vaccination status are sham reasons being used to impose the real agenda of “techno-authoritarianism”.

                                                                                      1. 2

                                                                                        What people are telling you is that the quoted section of your post sounds like one of those paranoid rants, in that it can be read to imply that contract tracing and vaccination status are sham reasons being used to impose the real agenda of “techno-authoritarianism”.

                                                                                        They’re worse than sham reasons to impose the real agenda of techno-authoritarianism - they’re superficially good reasons to impose the real agenda of techno-authoritarianism. Techno-authoritarianism is advanced more by a broad social atmosphere where opposition to software authoritarianism is widely thought of as low-status and uncomfortably adjacent to people with heretical politics, than it is by genuine conspiracies.

                                                                                        1. 3

                                                                                          Your formulation appears to be a literally irrefutable claim, in that anything and everything could be described, via argumentative gymnastics, as advancing or supporting “techno-authoritarianism”.

                                                                                      2. -2

                                                                                        Ignore them, they’re robots.

                                                                                      3. 2

                                                                                        Thank you for reading me correctly and providing this good summary of my comment

                                                                                        I would like to further clarify that I in no way meant to assume the rant was in bad faith (as someone in the Free Software movement, I could see the intent) but only that it would be easy to read it that way and thus distract from the meat of the article.

                                                                                      4. 3

                                                                                        I don’t think those three paragraphs make you out as a crank. I think it is fine and good to ask for serious privacy protections in contact-tracing, vaccine passport, and identity systems.

                                                                                        I would like to point out that many liberal democracies require their citizens to carry ID with them at all times. I believe this is the law in Germany and France, where I understand it is mostly used for harassing ethnic minorities.

                                                                                        FWIW, I think this history could be used to strengthen your argument: “liberal” democracies are very comfortable with authoritarianism for some of the population and these illiberal mechanisms are rarely dismantled, so they will accumulate if not resisted.

                                                                                        1. -2

                                                                                          a first-world liberal democracy.

                                                                                          In Australia

                                                                                          I think king Murdoch would disagree.

                                                                                        2. 5

                                                                                          Being anti-government is not immoral per se. It depends on the government. For example, you would probably agree that it’s moral to be anti-government in North Korea. You don’t have to deny Covid, the respiratory disease, to see that some governments have massively overstepped their boundaries. For example, there is mounting evidence that dusk-to-dawn curfews have no impact on the pandemic situation whatsoever, yet they were broadly imposed, often violating the constitution of the respective country. I would appreciate if people like you would stop with the moralistic shaming and inspect the subject matter with more care and thought. Not everyone who criticises the measures or aspects thereof is a science-denying anarcho-terrorist.

                                                                                        1. 14

                                                                                          This is actually a significant development for people who write GUI code in Rust. Finally we have a solid release of Rust bindings for GTK 4. In addition to that, the libhandy Rust bindings [1] allow for better development of Linux phone apps like for the PinePhone or the Librem 5, so an update to that crate is welcome too [2]. While GTK is not perfect, is is one of the few ways to write robust and usable GUI programs in Rust. Let us thank the developers for all the hard work that went into this release. The gtk-rs people work tirelessly and helped me out numerous times when I asked questions on IRC.

                                                                                          [1] https://gitlab.gnome.org/World/Rust/libhandy-rs

                                                                                          [2] https://crates.io/crates/libhandy

                                                                                          1. 2

                                                                                            Note that libhandy is for GTK3; the GTK4 equivalent is now libadwaita.

                                                                                            1. 1

                                                                                              Have you built (or even used) anything that targets Mac OS or Windows using GTK bindings? How does the end result feel on those platforms, and how hairy is it to build?

                                                                                              1. 10

                                                                                                Yes, I build for Windows but not Mac OS. You can actually cross-compile on Linux targeting Windows. That works well out of the box, I’ve tried it. You can also compile on Windows for Windows. That requires MSYS2 and a bit of configuration, but it’s not the end of the world (I avoid Visual Studio if possible and go with GNU tooling). The entire thing, along with build instructions, can be found here: https://github.com/BenjaminRi/Sherlog

                                                                                                As for the end result. My Windows users install the application with a Nullsoft installer which I generate with NSIS script. The installer puts all the files and dlls in the proper places. All the GUI elements behave as expected. It could look prettier. But it supports styles, so you can do a lot with styling to make it look good. Qt would probably look better, but the C++ bindings are an obstacle for Rust programmers. I don’t really care about looks, my application is a developer tool. For some elements, I had to implement my own manually rendered GUI elements on a plain canvas because I require insane performance that no GUI toolkit will deliver (not just GTK’s fault). You can get a lot out of GTK if you use it correctly, it can absolutely produce programs that are daily drivers. But it will never look exactly native. I use GTK because I want to support both Linux and Windows.

                                                                                                1. 1

                                                                                                  That looks much better on Windows than I expected it to. Certainly very serviceable for dev/admin tools. I like that the cross compiling works well out of the box. I’ve avoided exploring a GUI kit in any depth so far for Rust, but this clearly needs to go on the list for when that time comes.

                                                                                                2. 4

                                                                                                  (Note: not OP). I haven’t tried running Rust on Windows, but GTK itself is pretty easy to build and use on Windows, see e.g. https://www.collabora.com/news-and-blog/blog/2021/03/18/build-and-run-gtk-4-applications-with-visual-studio/ , https://www.collabora.com/news-and-blog/blog/2021/04/29/build-your-own-application-with-gtk4-as-a-meson-subproject/ (no affiliation, Collabora is just a big contributor on this side).

                                                                                                  That being said, it’s very much the Gnome toolkit these days. It’s a pretty bad choice for cross-platform development.

                                                                                                  1. 5

                                                                                                    That being said, it’s very much the Gnome toolkit these days. It’s a pretty bad choice for cross-platform development.

                                                                                                    In particular, note that GTK doesn’t implement accessibility (e.g. for blind people using screen readers) on Windows. Not sure about Mac.

                                                                                                  2. 4

                                                                                                    I have built an application using GTK via gtk-rs. gtk-rs is really nice for writing applications is you are targeting X11 or Wayland. I am not a big GTK fan (I strongly prefer Qt), but gtk-rs makes writing GTK applications quite pleasant.

                                                                                                    I also built the application for macOS and the result was… horrific? Rendering was awfully slow and there was virtually no platform integration, making the application stick out like a sore thumb.

                                                                                                    Since most of the application logic was not in the GUI and there is no good support for Qt in Rust, we ended up rewriting the application in PyQt and using the main logic through PyO3 (Rust <-> Python bridge). This worked like a charm and the application felt near-native on macOS.

                                                                                                    1. 2

                                                                                                      I’ve written a gtk3-rs app on macOS and it was “meh”. It is better integrated than an average Electron app or egui, but it’s still obviously not native. I’ve also run into some rendering performance problems on macOS that weren’t an issue on Elementary.

                                                                                                  1. 2

                                                                                                    isn’t this like with c/c++/java/javascript previously ?

                                                                                                    1. 25

                                                                                                      No, it’s different. I know C++ for a long time and mainly write C++ in my full-time job for years, but with Rust, I’m about 5 times as productive as with C++. Since I learned Rust, I churned out various programs that I would’ve never been able to develop in C++, simply due to time and complexity. I can now write software that I previously couldn’t have developed as a single person. Say about the language what you will, to me personally, Rust is pure empowerment that manifests in real software that is used by real people daily and saves time, money and nerves. And trust me, in the years before I learned Rust, nothing annoyed me more than the Rust evangelists whose posts kept popping up in every forum.

                                                                                                      1. 4

                                                                                                        Is there anything you could share that you feel is a particularly good example of something you’ve been able to develop in Rust on your own that you couldn’t have otherwise?

                                                                                                        I’m asking because I am learning Rust for fun right now, and I’m hitting the wall a little bit. (By that I mean “the wall” in the same sense that people who run endurance races use the term. You hit a certain point in the race where you suspect you won’t be able to continue. If you can push past that, you can have a good long race. But it’s a challenge.) I can get things done and there’s a lot that I like about it, but I don’t feel very productive yet.

                                                                                                        I’ve mainly written C++ and python over the past 20 years, so if it’s something you could show, seeing some of the things you’ve churned out with Rust that you couldn’t previously would be really interesting to me as I’m deciding whether I can afford the energy/aggravation to “push through”.

                                                                                                        1. 8

                                                                                                          Is there anything you could share that you feel is a particularly good example of something you’ve been able to develop in Rust on your own that you couldn’t have otherwise?

                                                                                                          Sure, these are some of my spare time projects:

                                                                                                          Of course all the things that can be done with Rust can also be done with C++… It might just take a decade longer to implement and fix until it’s stable ;)

                                                                                                          The projects above are of a size that pushes the boundaries of what I as a single individual can create and maintain in my spare time. I can confidently say that Sherlog would have never happened with C++.

                                                                                                          1. 3

                                                                                                            Thanks! That’s exactly the kind of thing I wanted to look at.

                                                                                                            I’ve learned new languages/libraries/frameworks enough over the years that this part isn’t surprising. I’m at that miserable point where every time I try to do something new, I spot a way to maybe do it, then spend a while looking at documentation to get it right, and in some cases spend time casting around search engines, forums, chat, etc. to find out what’s best/idiomatic.

                                                                                                            Some of this feels a little harder with rust than other things, but probably isn’t really. This is just the slow part of learning something.

                                                                                                            So it’s helpful to see those projects that you consider the “payoff”. Plus Sherlog looks neat. Thanks for sharing it.

                                                                                                            1. 1

                                                                                                              Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. If you aren’t sure which way to do something, do it both ways and see which works better.

                                                                                                              John Carmack

                                                                                                              Also, the Rust Discord is frequented by super nice and helpful people. They helped me more than once when I got stuck. Same thing with the gnome IRC, they also have a dedicated Rust channel.

                                                                                                          2. 4

                                                                                                            Personally its: If it compiles, it’s nearly done. I don’t have to think about += vs append - which in python might just change a lot of what is happening (rust won’t just nest two lists without me realizing, because types..). Or that I don’t have to worry about using c dependencies and their quirks that much (if at all with some very good bindings). Other than that: Yes it takes some time to get really productive. Till you acquired your base of crates and “framework” to re-use for most things (in which you can look up some of your specific solutions).

                                                                                                            1. 2

                                                                                                              100% agree here. Not a major rust user, but when I do it is both annoying and really nice how the compiler checks what I would usually catch in manual testing and debugging.

                                                                                                        2. 7

                                                                                                          Well, it’s a wave, they come and go :)

                                                                                                          1. 1

                                                                                                            Hahaha nice one, I’ll chill on a sandy beach of C/Fortran/Python and mine some coins =)

                                                                                                        1. 5

                                                                                                          I wanted to do the same thing, but then I realized it isn’t worth it. My internet is slower than 1 Gbit/s, and the disks in my NAS are about 1 Gbit/s, so my bottleneck isn’t really Ethernet at the moment. Also, these 10 Gbit/s switches require way more power, which means a higher electricity bill.

                                                                                                          1. 5

                                                                                                            Put a 1T NVMe SSD as L2ARC for your NAS and 10Gbps can have a meaningful difference. Especially for SMB which doesn’t seem to have any local caching supported in either macOS or Windows. Seek and play will be much faster than 1Gbps connection because the content will be cached better on NVMe and it can be comfortably served faster from NVMe cache.

                                                                                                            My current problem is pretty stupid. zbackup seems not work well with sshfs and it cannot remotely reach any meaningful speed when doing the backup, not even mention 10Gbps …

                                                                                                            1. 3

                                                                                                              Which is true for 99% of lobsters, 10G is still an overkill unless you d bulk transfer daily or having access to a better uplink.

                                                                                                            1. 3

                                                                                                              The ESPRESSObin: https://espressobin.net/

                                                                                                              We used this board at work to evaluate the platform, we then built our own hardware based on this SoC. Linux worked out of the box like a charm. Was a real pleasure to develop for this.