Which language gives users more control, C++ or Rust

Just to show how both C++ and Rust are evolving, there are different things that you can find in one language and missing in the other.

Rust is gradually implementing constant time function evaluation, and the road for variadic generics seems to be still long. Instead, in C++17 we gained if constexpr to help with constant time metaprogramming, and the fold expressions now allow to complex things without compile time recursion.

On the other hand, it is impossible, at to date, to perform a destructive move in C++, which is a regular and simple move in Rust. Experienced C++ programmers also know that in the Standard template library, an iterator when deferenced must return a reference, disallowing any form of adaptor or smart accessor. This last thing will change with the introduction of a very basic form of the so-called ranges. Rust does not have all these issues, because iterators work in a totally different way... and if you ever implemented an iterator in C++, you already know that the Rust way is much easier.

IMHO, it is always good to have evolving languages like C++ and Rust which have the same aim (full control, zero overhead abstraction and so on) but different ideas about the goals have to be reached. Take a simple example: coroutines! Both languages are trying to stabilize this (old) concept, and they will probably find different approaches.

Final note: we are not considering other languages like Haskell, which is very powerful. I cannot say anything because of my ignorance, but surely other people like @Centril could probably assert that there are things in which Haskell wins over Rust and C++

Saying that a language is better/more powerful than another in absolute is probably limiting and conceptually erroneous.

3 Likes

My suggestion is to learn PIC assembly programming An Introduction to PIC Assembly Language Programming | Microcontroller Tutorials

Software people don't go to that level (or very rarely do), it's more for computer and electronic engineering peeps. That's also the lowest level you can possibly go before actually buying logic gates and sticking them in a protoboard, wiring them up to do the base level logic gate programming.

Another low-level thing to do is to learn to program FPGAs Cost-Optimized Portfolio

Both for PICs and FPGAs use the Development boards you can find at your nearest electronic hobby shops.

After learning PIC programming, you can conceivably learn Rust as a way to increase your PIC programming productivity - this is where you will understand "zero cost abstraction". FPGAs can't be programmed in Rust because you need a hardware-descriptive language for that, although there could possibly be a way to convert Rust to VHDL.

VHDL will be much different from 'normal' computer programming. The hardware inherently generates parallel processing and the bottom part of your code will compute at the same time as the top part of your code. Then there are various timing issues you will need to address in the asynchronous parts of the program. There's a reason why FPGA programming is much less widespread, to say the least. But, you can plug in libraries that simulate CPU cores with FPGAs - allowing you fine-grained control over a CPU implementation in the debug stage of the hardware-software interface.

3 Likes

Have you looked at university programs in the fields that you are interested in? You just will not be able to unlock your full capabilities unless you have proper guidance on the matter, and university tuition is, as of now, still the only way to get proper guidance.

It looks like you have not done much programming? I'd say perhaps you should go the other direction and start with python. You need to become familiar with control flow and reasoning about problems while translating them into computer code. The fastest way to learn that is via Python, and the video support there will be even better. C++ is certainly more of a computer science/engineering language - there are things you can do with C++ that you will likely never learn from videos, only by studying university textbooks on the language. Like, try doing pointer dereferencing to a function and calling the function with pointer arithmetic to get what I'm saying.

2 Likes

Learning programming through watching videos has to be one of the worst ideas I've ever heard. You kids these days? :wink: Seriously, though, learning a programming is about reading (intensive reading) and doing. Watching videos is only useful in the most rudimentary sense for introductory purposes. If you are trying to break into software development, and you don't like learning through reading, you might want to consider a different profession. I can't imagine ever being successful by wanting to learn programming through video tutorials (primarily).

4 Likes

I've found video tutorials very useful for visual things like CSS, but yeah, otherwise written tutorials seem to work the best for me as well :slight_smile:

The problem is most tutorial video uploaders present in small fonts and does not give viewers enough time to type the code....

I prefer to not stick to tutorials or videos because people often end up blindly following that person without reasoning on why they are doing a certain thing or whether they should do it or not.

This is not very helpful. Please phrase your suggestions more constructively, and leave out language like "worst ideas I've ever heard."

12 Likes

[One post hidden. I will reply to it privately. Please contact moderators directly to discuss moderation and policy.]

2 Likes

I have been thinking about this question quite a bit in time I should have been sleeping...

Once apon a time I programmed extensively and deeply in C++. Loved it. I loved the freedom and the access to low level programming with high level tools (like the STL) at my finger tips.

Coming to Rust I was offended (truly) by having the case and style of variable names being commented on by the compiler. (In the day I had my on style). I have spent long times struggling with the borrow checker. I am used to using my own style of memory management and was proud that I did not trigger memory leaks.

I am still a beginner in Rust, I still have not got the idiom down pat. But, older and wiser, I have gotten over myself and I appreciate the need for the restrictions enforced by Rust. I am over my own hubris and find that if I toe the Rust line I will be as productive in Rust as I as in C++. And I will have the same very low run time overhead and rich data types.

I do not think I am answering the question as asked (I think related to control over hardware) but IMHO Rust gives much less expressiveness, I have much less control over my programming paradigms (I do not have the control given by C/C++ pointers). But in return I have a much smaller ball of string to unravel. In C++ there I had control over every aspect of the programmes I wrote. To the point where, even in 2001 when I left C++ behind, people were strictly subsetting C++ so a group could work on it and understand each others code. (Every group seemed to have a different subset). Over the years C++ has become a place to put every programming concept and style. That is (was?) its purpose, but has made it so huge that it is unwieldy.

Rust gives me much less control. I am re-factoring my code constantly to keep the borrow checker happy. And my code is better for it.

I am old and grey. I never thought I would see anything in computing that ould really impress me like the STL did in 1997. But by golly you've done it with Rust.

So I am happy to abandon the control that C++ gave me. I liked it, but it as the zero cost (mostly) abstractions that was what I really appreciated in C++. In Rust I have them still, and it is making me a better programmer.

Yay for Rust!!

15 Likes

I ran across this a couple of days ago, but it's the summary email that resulted in me actually replying. Most of the decision between the languages is personal, and there are considerations to be made. If you know neither, both of them have sharp edges (but Rust is far more telling "what went wrong"). If you know one, and are coming to the other (like I'd suggest many did with C++ then coming to Rust), then you'll have a bias (at least at first). My journey started off not like Rust at all (but it was pre-1.0, so every language change resulted in me having to re-learn something while working in Go, C++, Python, JavaScript, and Lua), but as it stabilised (~2015), it grew on me (though there are still a lot of libraries I call from Rust that are written in C++ and accessed via a C library!).

I'd say C++ seems to give you more control, but it's an illusion due to Rust's implied safety. I say "implied safety" because unless you explicitly opt into the unsafe code regions (like most of my code does for speed), you are safe, provided the code you use is safe (beneath the hood a lot of safe code uses unsafe methods to get you speed and access -- they are usually checked and made safe, but they're still written in unsafe blocks or functions!). It's a bit of a nitpick, but to me it's an important one. In C++ I leave comments for people to find the scary code (because often it's hard to determine if (**pObj) is unsafe or just getting what the pointer to a pointer is pointing at to use it, let alone grok it quickly); in Rust unsafe fn prevents me from having to explicitly write "HERE BE DRAGONS" (though I do that anyway when it's particularly scary that can go wrong).

Borrow checker issues aside (they're known and being fixed(?)), you can do almost everything insane you want to do in C or C++ in Rust. The one exception I've come across thus far is hotpatching (which is basically irrelevant for the reasons you're asking), and can be done in ways that aren't ideal (though the stability concerns in question for real hotpatching are terrifying, and outside of a virtual machine, like BEAM, it's not always a good idea -- unless you like coworkers screaming at you).

If the question is "which has more features that I can exploit for ", Rust can use C libraries, and C++ can be built into C libraries to be used in Rust. I've moved from C++ to Rust (and Go) in most of my personal and private projects because I prefer the safety the compiler offers me. I now ask myself, "should I be using unsafe?" (Okay, I don't do this enough, but I should, and it's a reminder every time I type unsafe that I'm the kind of person who writes way too much of it; this reminder has resulted in me writing more safe code (though it usually gets rewritten for speed later).) The advantage of this is you start off writing sane code (that isn't super performant) first. You know it works, you know what it does, what it's meant to do, and you can maintain the API (at least externally). You can then write a faster version, wrap it up behind a feature (as a guard), and bam, best of both worlds.


As for the video/text debate, I query the video part. Not because there aren't multiple kinds of learners (visual, audio, etc.), but because the video requires you to split your focus in a different way. You don't "pause" a book like you do video and audio, and they can give you information that's an aside; it's a bit like reading a map compared to relying on a GPS, where one requires you to process the information and store it in your memory (the map), the other feeds it to you and reduces how much you need to use that part of your memory. Sure, there are theoretically upsides to the GPS in this (and thus so too the "video"), but I'd prefer to buffer the information in my brain so I can mull over it, and fall back to the "look, cover, guess, check" style of learning. It's a personal preference, sure, but I can't help but feel that better exposure is more helpful. It also means I can review it in ways that are frustrating with a video.

Regardless of the learning angle you choose, be aware you'll be spending a lot of time reading. If for no other reason than it's very unlikely the API is going to be turned into a useful audio or video resource, and the constant moving target of all of the crates (and their documentation) means that short of generic text-to-speech, you won't see much; I don't agree with the way it was put before, but reading and constantly learning is the way of information technology.

For visual things, like visualisation, game design/engines, and the like, video supplements can be great. I'm not saying they're bad, but in reality I question how a screenshot isn't almost always as good for the basics -- only for animation do you really need more for verification.

5 Likes

joe232 sorry , but it looks like you are quite new to both - programming and system works background, and now you are trying to take in "everything at once". i see no good (for you) in it. The questions you posted on the forum were answered but i'm afraid none of the answers will satisfy you for they are not connected with your own skills and knowledge - so they are quite useless for you. Perhabs, you should do your best with system work background and just after to ask such questions being more specific with the problem or the application field. I believe that C lang is optimal for beginner's low to middle level programming tasks (more over - it is native for most of hardware pieces ). You may switch to Rust or C++ (or whatever you want or need) as growing more potent and experienced.

2 Likes

I'm not sure I'd agree there.

C itself is simple because it assumes the programmer will also understand all the relevant idiosyncracies of the underlying machine model, which at least doubles the set of knowledge you need to write safe, reliable code.

...and the compiler isn't very good at warning you when you violate them and set yourself up for bugs that are hard to diagnose or which could lay dormant until the worst possible time.

6 Likes

C itself is simple because it assumes the programmer will also understand all the relevant idiosyncracies of the underlying machine model, which at least doubles the set of knowledge you need to write safe, reliable code.

No. Understanding of "all the relevant idiosyncracies of the underlying machine model" (along with OS architecture models) is crucial part of successfull system level programming activity. C-lang was designed to follow them as much as possible with no overhead - so the required knowledge is not doubled (as in Rust or even C++ cases).
But system programming is apriory more complex than most of things that the beginners usially have deal with.

ā€¦and the compiler isnā€™t very good at warning you when you violate them and set yourself up for bugs that are hard to diagnose or which could lay dormant until the worst possible time.

hehe if i were joe232 - the cleverness of the rust compiler would be least thing i should care of....

1 Like

The problem is that, if you misunderstand the machine model, C is likely to just silently do something that seems right... until the worst possible time.

I don't consider that conducive to learning.

5 Likes

This is not actually true. C is designed to provide a simple representation of a machine with a flat memory model, which is not how modern hardware actually works. I found this quite enlightening, and I hope it helps you as well: C Is Not a Low-level Language - ACM Queue

9 Likes

x86 assembly is a high-level language

5 Likes

thanks for the link but... i'm quite aware of the issue :smiley:
You should take in your account:

  1. i adressed solely to beginners in both aspects (programming and system background) like joe232.
  2. There are some models to describe current situations in more correct way, but old good boxes+linear adress space is still very handy like newton mechanics in the modern epoch of special (or general) theory of relativity..
  3. Actually system programming languages (and Rust, by the way) relays on the memory model that came from C-lang epoch - no more.
  4. so on....(i ' m lazy and not from native english speakers to make opuses like aws), sorry.

true (in somewhat).. yet it is strictly hardware related (much more than C-lang) -and (i believe) it is not the topic related issue.

Very informative. Thanks for posting that.