Live data from Hacker News

C++ For C Programmers

coursera.org

21–30 of 53 posts

Re: C++ For C Programmers

#21
post #4

Nice! However, I'd appreciate the converse more. I'm pretty well versed in C++, and every time I try to write something in C, I fall back to C++. I find memory management a pain without RAII, error handling a hassle without exceptions, and, well, anything really a pain without some sort of standard container library. I have the idea that there's good alternatives for these in C-land, but I'm unfamiliar with them and…

Use GObject (https://developer.gnome.org/gobject/stable/) and GLib. GObject is basically a bunch of macros to let you write OO code in C, GLib is a cross-platform set of libraries with somewhat of a 'standard library' of data structures, string handling stuff etc. It's the foundation of Gnome, it's also LGPL so that may be an issue. To be honest though I've never used it for strictly C-only code, I've only used it on Linux with gcc and it was 10 years ago.

Still, it's a nice hack for when you want to write C++-like code while still using C constructs only.

Re: C++ For C Programmers

#22
post #11
post #2

I'm slightly afraid to learn C++ after being told so many horror stories. But for the low low price of free? Count me in.

Forget about the stories. I have quite some experience with both C and C++, started with C. There's horror in both of them, if you do it wrong enough. Oh yes there's more horror in C++, there are more ways to do it wrong. But in the end it comes down to the same: learning curve. If you know it well enough there's no horror anymore, just joy.

Agreed, specially since C++11 provides better mechanisms for writing safe code if one needs to stay in C++ world.

Now C is a different matter.

Re: C++ For C Programmers

#23

Earlier quoted context omitted.

You're the first person i've heard of who falls back to C++, if that data point is of any value. AIUI exceptions and RAII are mutually exclusive in C++. I don't know enough about C++ so i wouldn't be surprised to find out this is wrong.

Exceptions and RAII match well, actually. Managing resources via RAII means that when an exception is thrown, the destructors of local objects are invoked so they'll release resources they've acquired. In fact, I'd argue that you very often have to use RAII with exceptions, since there's no 'finally' block on a try-catch statement and hence it's the easiest way to ensure stuff gets cleaned up (well, except for catch(…

correct me if I am wrong but you can't rethrow in a destructor and hence RAII is required if you are using exceptions - because the cleanup and reporting work must be done in the destructor - unless you use global state to track failures and check after every attempted release of a resource i.e. C error checking.

Re: C++ For C Programmers

#24
post #4

Nice! However, I'd appreciate the converse more. I'm pretty well versed in C++, and every time I try to write something in C, I fall back to C++. I find memory management a pain without RAII, error handling a hassle without exceptions, and, well, anything really a pain without some sort of standard container library. I have the idea that there's good alternatives for these in C-land, but I'm unfamiliar with them and…

You're the first person i've heard of who falls back to C++, if that data point is of any value. AIUI exceptions and RAII are mutually exclusive in C++. I don't know enough about C++ so i wouldn't be surprised to find out this is wrong.

> You're the first person i've heard of who falls back to C++, if that data point is of any value.

Every time I write C code is at a gun point of being forced to do so. When I have the choice between C++ and C, I always pick up C++.

Re: C++ For C Programmers

#25
post #4

Nice! However, I'd appreciate the converse more. I'm pretty well versed in C++, and every time I try to write something in C, I fall back to C++. I find memory management a pain without RAII, error handling a hassle without exceptions, and, well, anything really a pain without some sort of standard container library. I have the idea that there's good alternatives for these in C-land, but I'm unfamiliar with them and…

You're the first person i've heard of who falls back to C++, if that data point is of any value. AIUI exceptions and RAII are mutually exclusive in C++. I don't know enough about C++ so i wouldn't be surprised to find out this is wrong.

Not sure what AIUI means, but the very words "exception-safe" usually imply RAII.

Re: C++ For C Programmers

#26
post #13

On another note: people claiming "C/C++" skills usually have neither.

That is exactly right... It is like they are assuming that by knowing C, then implicitly they know C++. That's tremendously wrong and they will notice that as soon as they work on a non-so-small project.

Re: C++ For C Programmers

#27
post #4

Nice! However, I'd appreciate the converse more. I'm pretty well versed in C++, and every time I try to write something in C, I fall back to C++. I find memory management a pain without RAII, error handling a hassle without exceptions, and, well, anything really a pain without some sort of standard container library. I have the idea that there's good alternatives for these in C-land, but I'm unfamiliar with them and…

You're the first person i've heard of who falls back to C++, if that data point is of any value. AIUI exceptions and RAII are mutually exclusive in C++. I don't know enough about C++ so i wouldn't be surprised to find out this is wrong.

I've tried several times to write new projects of mine from scratch in C just for a challenge, and have gone back to C++ every time.

Re: C++ For C Programmers

#28
I heard awful things about this course. Just check the reviews for it's textbook: http://tinyurl.com/cppcprog

In general, anything that says "X for Y programmers" is not worth it.

If you really want to learn C++, and you already know C, I suggest either "Accelerated C++" or "The C++ Programming language"

Re: C++ For C Programmers

#29
post #6
post #5

>Please use a modern browser with JavaScript enabled to use Coursera. One wonders how people who can't even create a static HTML page will manage to teach people a complex language like C++.

Because this University of California professor runs the entire Coursera website.

Well I don't know anything about who this organisation is or who in particular is running the course because I can't view the website!

Re: C++ For C Programmers

#30
post #21
post #4

Nice! However, I'd appreciate the converse more. I'm pretty well versed in C++, and every time I try to write something in C, I fall back to C++. I find memory management a pain without RAII, error handling a hassle without exceptions, and, well, anything really a pain without some sort of standard container library. I have the idea that there's good alternatives for these in C-land, but I'm unfamiliar with them and…

Use GObject ( https://developer.gnome.org/gobject/stable/ ) and GLib. GObject is basically a bunch of macros to let you write OO code in C, GLib is a cross-platform set of libraries with somewhat of a 'standard library' of data structures, string handling stuff etc. It's the foundation of Gnome, it's also LGPL so that may be an issue. To be honest though I've never used it for strictly C-only code, I've only used it…

Thanks for the suggestion, I'll look into it.

That said, my first underbelly reaction is that I don't want to write C++-like code in C. Why would I do that? I might as well use C++ then. It's like writing functional code in Java. It's possible, but it's a hack.

What I'd like to learn is how to decently deal with memory, exceptional behaviour, common data structures, etc in modern idiomatic C. Some other people in this thread made some nice suggestions for that, btw, so thanks guys :)

Post reply on HN