4 ms·
You can do this kind of type oriented programming in C++, unfortunely as many people only use it as a better C, this knowledge is seldom widespread, and even wh
by pjmlp 1y ago
You can do this kind of type oriented programming in C++, unfortunely as many people only use it as a better C, this knowledge is seldom widespread, and even when demoing, it needs a lot of advocacy alongside compiler explorer to actually make the point across.
And then the audience will nod yes, accept the message of what is possible, and go back to whatever approach they were doing already.
- ultimaweapon 1y agoRust give more ergonomic to this. In C++ it need a lot of typing for creating a new type compared to Rust.
- pjmlp 1y agoDepends pretty much on the type, if using templates or not, if being anti-macros or not. It isn't the typing, rather the culture.
- tialaramex 1y agoRust's type system is a technology, but technology can be used by a culture to support its goals. The technology alone will not get you there, so the culture is more important, but we do need both for success.
- jeroenhd 1y agoYou need to add a lot of text, but the text contains about the same semantic meaning. It's a lot of typing but that's a matter of density rather than ease of use. At least in modern c++. Then again, modern C++ seems to play the same role as modern Java, in that some places use it but most of them are stuck at the version they picked when they started developing on a piece of software decades ago.
- pjmlp 1y agoTo be fair to modern C++, or lack thereof, I would assert most places being stuck with specific versions applies to any programming language that traces back to the 20th century. Turns out updating software versions in most companies is really hard, and updating humans atittude to specific programming practices even harder, unless their job is on the line.
- vlovich123 1y agoRust has solved the problem of upgrading at the language level - you can mix’n’match modules targeting different revisions of the language just fine and you can mix’n’match multiple versions of the same library within a single binary. It makes the whole thing possible to do piecemeal.
- pjmlp 1y agoOnly if there are no incompatible changes on the standard library, public interface or observable semantic behaviours. And even so, it doesn't matter if IT says no, or the customer doesn't pay for consulting services to upgrade existing projects.
- vlovich123 1y agoI’ve never seen IT be involved in a decision about the language edition being selected by a development team or even which dependency to pick. As for consulting, that’s a different type of world that’s not the best example of good software development practices. As for incompatible changes, there aren’t any in Rust by design. That limits some of the changes they can make even in an edition but in practice it works ok. Even over a longer time span, I think the Rust community will figure out a way to trim irrelevant cruft away.
- pjmlp 1y agoIt happens all the time, in many companies IT decides the images used on the build servers, or cloud instances for developers. I am not so optimistic when Rust achieves a similar market share and historical baggage, as C and C++ have today, growing since the 1970's. It is of course better designed, and with better tooling, that doesn't spare it from market forces and companies sponsoring the foundation. See where Linux foundation is today for a comparable example.
- William_BB 1y agoOut of curiosity, how would one go about implementing this in C++?
- pjmlp 1y agoThe bare bones skeleton to start exploring the ideas would be something like this, https://godbolt.org/z/Wcend5rT3 https://godbolt.org/z/Wcend5rT3
- tialaramex 1y agoAlso Rust's borrowck means you can often design an API where it's really easy to fall into our old friend the pit of success with these wrapper types. Both Rust's OwnedFd and Rust's Mutex<T> have analogous C++ which are used, but lacking a borrowck C++ can't express the idea "Maximum of one person can have this" What happens if I keep a mutable reference to the Goose despite unlocking the protective mutex? In C++ the answer is you lose mutual exclusion, in Rust that doesn't compile. C++ people will say "Don't do that" but "not doing that" does not scale whereas it doesn't compile scales just fine.
- pjmlp 1y agoWhile you are right if we are using the languages on their own, like clippy is common usage on Rust land culture, it is a matter of how much similar tooling gets used on C++, which is sadly a matter of culture, or lack thereof.
- vlovich123 1y agoI’ve never seen static analysis c++ tooling that has precise errors, have you? It’s always a littered mess of useful and useless things and I’m not even so sure it would warn about holding on to an interior reference into a lock-protected data structure. Static analysis in c++ is akin to clippy but without a --fix option and many more false positives. Also clippy is more about stylistic consistency within the ecosystem and completely optional, not about safety which isn’t optional.
- pjmlp 1y agoDepends on which tools, clang tidy can be customised, Apple just did a talk at C++ Now about their custom checks for Webkit "Safe C++". Commercial tools like PVS and Coventry, or those used in high integrity computing, also allow for rule customisation. However the first step is to use anything at all, a challenge since lint was born in 1979.