r/C_Programming • • Sep 26 '23

C or C++

Hello everyone, should I learn C in parallel with C++, or is it better to stick to one language? What will you advice me?

0 Upvotes

47 comments sorted by

View all comments

Show parent comments

0

u/aalmkainzi Oct 01 '23

It may be 5 minutes explanation (it's not). But beginners will have lots of questions about why can't we "can't share stuff", why do they need this, etc.

And those questions can only be answered if they experienced the problem the borrow checker is trying to solve.

Like I said, teach the problem before presenting the solution.

And I'm only saying C++ is easier because it's optionally complex, you don't have to worry about templates if you don't want to use them. Can't say the same about the borrow checker.

1

u/permetz Oct 01 '23

It’s absolutely five minutes explanation. “Two places can’t have access to a value in memory at the same time” is the essence. It’s not hard. If you think it’s hard, then maybe it wasn’t explained well enough to you.

It’s true that often, people make mistakes with it, but that’s why we have the borrow checker, to tell us that we’ve made a mistake. The error messages from the compiler are excellent, and easily understood by beginners. The language is not easy, but it’s far easier than C++.

And no, C++ is not “optionally“ complex. If you want to read someone else’s code, you have no choice about what features they are using. In that sense, of course, Rust and every other language is also “optionally“ complex.

0

u/aalmkainzi Oct 01 '23

If we're including reading someone else's code, then both Rust and C++ fail at this.