Live data from Hacker News

Popular Myths about C++, Part 1

isocpp.org

101–110 of 144 posts

Re: Popular Myths about C++, Part 1

#101
post #32

Earlier quoted context omitted.

Linus has ported his Subsurface project to Qt, thanks to the current state of affairs in Gtk, so I imagine he might be a bit more welcoming to C++ nowadays.

https://github.com/torvalds/subsurface pretty interesting! the .c's heavily outnumber the .cpp's. there's nothing like having your prejudices confirmed to harden them, so I question whether he is more welcoming.

There's a video about it https://www.youtube.com/watch?v=ON0A1dsQOV0

Apparently, Qt takes away most of the problems they have with C++

Re: Popular Myths about C++, Part 1

#102
I like C++, but using it to teach beginners who have no knowledge of C or compilers in general is a horrible idea. My college CS101 course was taught using C++, and I was lucky because I already knew multiple programming languages before that.

1. There are a lot of abstractions in C++ that make it very powerful, but the reason those exist would be completely lost on a newbie. Pass-by-reference vs. pass-by-value? Oh yeah, there are pointers too that you might run into, that's almost exactly like a reference but with a different syntax. We have smart pointers instead to obscure that from you, but if you search for examples online you might run into any of these. But don't worry about all of this; these language features only exist because of type safety and performance which you have no clue about. Just change the syntax until it compiles and runs.

2. Programming is more than write->compile. Debugging is as important, if not more, and heaven help you if you're a beginner trying to debug C++. With C you'll at least get exposure to machine code that pretty much looks like the program you wrote.

3. C++11 is an improvement, but it's not ubiquitous and it adds abstraction that someone without a solid C/Assembly background will have very little chance of understanding.

Teaching C++ to someone with a firm grasp of C would be a lot easier and additive. "Here are the new features that can help the compiler make your program more performant or type-safe or fix your memory leaks." Otherwise you're throwing a bunch of solutions at students to problems they've never had.

Re: Popular Myths about C++, Part 1

#103

I like C++, but using it to teach beginners who have no knowledge of C or compilers in general is a horrible idea. My college CS101 course was taught using C++, and I was lucky because I already knew multiple programming languages before that. 1. There are a lot of abstractions in C++ that make it very powerful, but the reason those exist would be completely lost on a newbie. Pass-by-reference vs. pass-by-value? Oh y…

It is the end of 2014 and I am using C++11 on Windows, OSX and Linux without too many incompatibilities. Of course, you need the latest versions of the compilers but it's ubiquitous enough.

Re: Popular Myths about C++, Part 1

#104

I'm looking forward for the next part, as the last three myths are the ones I'm waiting for their answers, as they should be pretty interesting. C++ has come a long way, and I really feel C++ 11 could very well replace Java as a learning language for computer science students (I don't think it'd be a good choice for an introduction to programming for non CS students), and I see many benefits in this, the biggests bei…

My biggest issue with most garbage collection implementations is the lack of RAII. While I love the ease of reading and writing Python or Lua, I'd love to be able to create a local object, like an open file or a database connection, and have it destructed immediately on return.

Re: Popular Myths about C++, Part 1

#105
post #104

I'm looking forward for the next part, as the last three myths are the ones I'm waiting for their answers, as they should be pretty interesting. C++ has come a long way, and I really feel C++ 11 could very well replace Java as a learning language for computer science students (I don't think it'd be a good choice for an introduction to programming for non CS students), and I see many benefits in this, the biggests bei…

My biggest issue with most garbage collection implementations is the lack of RAII. While I love the ease of reading and writing Python or Lua, I'd love to be able to create a local object, like an open file or a database connection, and have it destructed immediately on return.

I'm not sure about Lua, but for Python it sounds like you may be interested in the "with" statement.

Re: Popular Myths about C++, Part 1

#106

What sort of C programmer wouldn't use snprintf to do the formatting? If the C++ program can use std::string then it's only fair to let the C program import . And honestly printf is so much nicer to use than iostreams I've always considered the relative ease of putting together a formated string one of C's strengths relative to C++.

What sort of C programmer wouldn't test for malloc() failing. Drives me batty to see articles where malloc() is happily assumed to always succeed.

If malloc fails for trying to allocate a few miserable bytes I would claim the game is over. Why would he need a fallback strategy, anyway? The program is tiny and really, really doesn't do anything important.

Matters of taste I suppose, but I've always felt that for tutorial and proof of concept code it's better to skip unnecessry details.

Not every line of code lives in a production environment...

Re: Popular Myths about C++, Part 1

#107

"Finally, which version is likely to be the most efficient? Yes, the C++ version, because it does not have to count the argument characters and does not use the free store (dynamic memory) for short argument strings." I just compiled the C code and the C++ code using: gcc -std=c99 -Wall -Wextra test.c -o test g++ -std=c++11 -Wall -Wextra test.cpp -o test According to valgrind: C: total heap usage: 1 allocs, 1 frees,…

Try it with optimizations on: gcc -std=c99 -O3 -Wall -Wextra test.c -o test g++ -std=c++11 -O3 -Wall -Wextra test.cpp -o test In my experience, C++ compilers are great at eliding temporaries and various constructor calls (and related memory allocations), but only if optimizations are turned on.

Made no difference

Re: Popular Myths about C++, Part 1

#108

Earlier quoted context omitted.

By not using them like in C. Of course this isn't an argument, but this shows that even though C++ doesn't prevent you from falling into the same trap that are present in C, it does give you the tool to at least allow you to do better than C to avoid these traps, notably thanks to RAII. Oh and let's not forget nullptr, which is a blessing compared to NULL. Pointers are still a feature of both languages. Pointers in C…

You need to understand so much about C to even talk about pointers in C++, and everything related to them, it's not funny. RAII -> Why? nullptr vs. NULL -> Why? Pointers -> Why? Don't use them in a certain way -> Why? The answer in all cases is C.

No, they are C++ pointers.

There are endless languages that have pointers, no need to talk anything about C.

Re: Popular Myths about C++, Part 1

#109

I like C++, but using it to teach beginners who have no knowledge of C or compilers in general is a horrible idea. My college CS101 course was taught using C++, and I was lucky because I already knew multiple programming languages before that. 1. There are a lot of abstractions in C++ that make it very powerful, but the reason those exist would be completely lost on a newbie. Pass-by-reference vs. pass-by-value? Oh y…

> Teaching C++ to someone with a firm grasp of C would be a lot easier and additive.

Where I took my CS degree, students were introduced to C++ straight after Pascal.

Re: Popular Myths about C++, Part 1

#110
post #61

Earlier quoted context omitted.

Yes, you can. I am having this discussion since 1993. Back when a I was teaching assistance in the late 90's, we never talked about C in our C++ classes, besides the initial history introduction. The fact that the C++ language contains a (almost) C compatible subset doesn't require students to be aware of it. It is all ANSI C++.

ok: why do structs exist and why are their members public? why don't you just use classes with public? i have been taught extremely poorly and am many years your junior. K&R/stan lipmann's "inside the C++ object model" was a huge "oh ok, I've been basically lied to the entire time"

> why do structs exist and why are their members public? why don't you just use classes with public?

To be able to reuse existing C code in a C++ compiler, while allowing them to participate in class hierarchies.

This is the real reason, but you don't need to explain it like that to new C++ devs.

Use struts when you just need a data container. Use classes when you need to add behaviour.

Simple rule, no need to talk anything about C.

Post reply on HN