←back to thread

In Defense of C++

(dayvster.com)
185 points todsacerdoti | 6 comments | | HN request time: 0.214s | source | bottom
Show context
jamesdhutton ◴[] No.45272875[source]
> You can write simple, readable, and maintainable code in C++ without ever needing to use templates, operator overloading, or any of the other more advanced features of the language.

Maybe you can do that. But you are probably working in a team. And inevitably someone else in your team thinks that operator overloading and template metaprogramming are beautiful things, and you have to work with their code. I speak from experience.

replies(1): >>45272967 #
1. dayvster ◴[] No.45272967[source]
This is true and I will concede this point. Appreciate your feedback!

However if I may raise my counter point I like to have a rule that C++ should be written mostly as if you were writing C as much as possible until you need some of it's additional features and complexities.

Problem is when somebody on the team does not share this view though, that much is true :)

replies(2): >>45273171 #>>45273270 #
2. digitalPhonix ◴[] No.45273171[source]
> However if I may raise my counter point I like to have a rule that C++ should be written mostly as if you were writing C as much as possible until you need some of it's additional features and complexities.

How do you define “need” for extra features? C and C++ can fundamentally both do the same thing so if you’re going to write C style C++, why not just write C and avoid all of C++’s foot guns?

replies(2): >>45273265 #>>45274164 #
3. dayvster ◴[] No.45273265[source]
Excellent question, I guess it depends on the team mostly how they define which features they need and which are better avoided.

As for why not just go for C. You can write C++ fully as if it were C, you can not ever turn C into C++

4. jbstack ◴[] No.45273270[source]
Counter-counter point: if you're going to actively avoid using the majority of a language's features and for the most part write code in it as if it were a different language, doesn't that suggest the language is deeply flawed?

(Note: I'm not saying it is deeply flawed, just that this particular way of using it suggests so).

replies(1): >>45273748 #
5. dayvster ◴[] No.45273748[source]
I wouldn't necessarily put it like that no. I'd say all languages have features that fit certain situations but should be avoided in other situations.

It's like a well equiped workshop, just because you have access to a chainsaw but do not need to use it to build a table does not mean it's a bad workshop.

C is very barebones, languages like C++. C#, Rust and so on are not. Just because you don't need all of it's features does not make those languages inherently bad.

Great question or in this case counter-counter point though.

6. bregma ◴[] No.45274164[source]
RAII. It's the major C++ feature I miss in C, and the one that fixes most memory leak problems in C. Also, std::vector, which solves the remaining memory leak (and most bounds problems) in C. And std::string, which solves the remaining memory leak problems.