Why would i use C++ over C?

why would i use C++ over C?

Use nim. It can translate your code to dependency free C or C++ as you wish. I'm not kidding.

why would i use nim over C?

Because it takes less lines of code and you can translate nim to C. I'm not kidding.

i would rather program in C directly

Good for you.
There were people saying that they'd rather program in ASM directly too. I'm not kidding.

I code in binary

Are you kidding me? I'm not kidding.

I code in dreams.

>tfw never clicked on that video

namespaces

>why

templates and constexpr. the occasional lambda. possibly RAII and move semantics.

You made this yourself didn't you? I have to say, and I do mean no offense by this, but that webm is fucking terrible. It is without question the worse I have ever seen in my life. Please, for the love of god never make anything ever again you suck

>being this new

>why would i use c++ over c?
-auto
-foreach
-classes(optional just like everythingelse in c++)
-digit separators (2'423'432'432'432'432)
-binary literals (0b10101010101)
-smart pointers
-much more type-safe
-much bigger standard library with full compatibility with the c standard library
-strings(if you think using char arrays is fun then try working with string matrices in c)

just a few things i randomly pulled out of my ass.a fully comprehensive list would be probably take hours to make.

Only meme answers in this thread..

The reason why you pick C++ over C is because your libraries demand it. If you only write fizzbuzz it doesn't matter at all. But when we talk about professional work you rarely start something from the scratch, but you work with existing programs and interfaces. So if you want to use C++ libraries you naturally want to use C++.

if you work with servers

why would you ever use C over C++ in this day and age. It's pretty much an objectively better and more powerful language.
Aside for OS programming that is.

Why is it so goddamn windy in her room?

My dad still does prefer ASM over everything else. Then again, he does have autism.

breddy much

it's the smell of govnocode swirling around

LOL YOU MUST BE KIDDING HAHAHA
GET A LOAD OF THIS GUY HAHAHAHAHA

I am not kidding

I'd rather you not use either. If you need to know why, you're just creating garbage code.

for this reason i'm already switching to C++, and i want to know what else i will get from the language, just like and said.

Simple reason is complexity.
>inb4 Linux kernel is coded in C

There are far more complex software than a kernel that requires a lot of people collaborating . Other reasons are the benefits that C++ offers in terms of OOP -- reuse, encapsulation, abstraction, polymorphism etc

>optional
Until you have to work with other people, of course.

better to rewrite librares in clear C than lern how to use all this shity useless features
Also it wil remove all memory leaks

Unless you are planning on using libraries of functions or planning on doing low level programming where you actually need to address the memory directly, pick literally any other language, c languages are hideous af.

i like the ideia, but it's not practical, not your most experienced programmer here.

i need STL for competitive programming

To use professional libraries like Qt, openCV and Eigen.

why would i use C over HTML+PHP+Javascript+CSS?

What advantages are there to learning C? I know operating systems are programmed in it but what exactly can I do with that knowledge?

Hello guys.

Can someone recommend to me a good place to ask questions about programming openGL in c++?

Preferably a place where i can ask a lot of REALLY DUMB questions and they won't get frustrated and just tell me to google it.

I occasionally ask you guys a question, but now i really need to ask some REALLY dumb questions, and i am not going to test y'all's patience.

That C++ Standard Template Library is pretty neat.
try freenode irc, it has lots of beginner friendly places.

As soon as you need any kind of container that is not fixed size or requires arbitrary keys, C just doesn't work anymore.
Type safety is is an amazing and important feature and C just lacks it. It even helps the compiler optimize.
You can even do things at compile time in C++, either via template metaprogramming or via constexpr. Why waste cycles?
C programmers usually get butmad about dynamic dispatch and its performance implications, only to shittily reinvent it.
And then there's convenience like the new pointer types (shared, weak, unique) which are awesome, references, move semantics, RAII...

C fucking stinks compared to C++. Any reasonably large and complex C program attempts to hide C's obvious flaws via macro magic, but that just results in code that nobody really understands anymore and that would have been simple to write in a natural manner in C++.

>C programmers usually get butmad about dynamic dispatch and its performance implications, only to shittily reinvent it.
Cfags will defend void* and qsort before they admit templates and std::sort are usually better.

No you don't. Haskell has more tools, so does Java. Both are easier to quickly shit-up some algo for your problem.
Russians use C++ because that's what they get taught at uni so they are mostly competent with C++.

void* is what I meant when I talked about how C lacks type safety and qsort is what I had in mind when I said that types help the compiler optimize.

No. Templates are useful, though not nearly as much as people who don't C think. In projects where C is chosen, we typically use few data structures optimized for our use-case so templates aren't a big win (i'd like templates for allocation though).
You also don't want to use algos from stdlib because they are optimized for some mythical "general case", i.e. they suck and you can do *much* better if you analyze YOUR data. Like using 4-way in-place radix sort instead of quicksort if your data is well-behaved.
Type-safety and void* is a big thing. That's why C is a very bad choice for writing applications, where you will have a need for generality. In systems there's no need for it because your system can be specified quite well. Who in their right mind would write a browser or a chat client in C? These are domains where garbage-collected high-level languages shine.

What's the difference between a template and a class?

I agree to some extent. The major motivation for using a language like C is to make and use hand-optimized algorithms data structures for the task at hand. However, not every operation is bottlenecking your program. In general it's useful to adopt the philosophy of only optimizing where necessary - and if some prefab container in the standard library isn't making a significant impact, then there's no point reinventing the wheel for it. I enjoy C++ for being nearly as expressive as C for creating specialized data structures but also having the STL for when I don't need to do that.

>Who in their right mind would write a browser or a chat client in C? These are domains where garbage-collected high-level languages shine.
Why are Chrome, Firefox, Opera, Vivaldi and pretty much every other web browser written in C++?

I use C in work, it just werks.

They're completely different concepts. A class template describes how to make a class; a function template describes how to make a function, and so on.
In C, a "generic" linked list definition might look something like this.
struct Node
{
void *data;
struct Node *next;
};
No type safety, and also indirection because you don't know how big your object is (you may actually be able to get it to work in this case without indirection using flexible array members but it's orthogonal to the point)
So the C++ way would be to define a way of instantiating a struct that is parameterized over another type.
template
struct Node
{
T data;
Node *next;
};
Node, Node and Node are all unique types with unique representations in memory.

std::vector

>why are browsers written in C++
Browsers are insane spaghetti skyscrapers built on top of a 30-story foundation of legacy code. C++ was the best option back when Gecko and KHTML were first developed.

In the space where C is used, not optimizing something might make your product 20% more expensive. The system is usually well-specified so you don't run into some ad-hoc performance problems, you chose algorithms and data structures in design phase, then you profile and do some adjustments- usually micro optimizations since at that point, changing algorithms or data structures won't improve your performance, unless you majorly fucked up like "oh i forgot that our input is only ever 16-byte chunks".
>Why are Chrome, Firefox, Opera, Vivaldi and pretty much every other web browser written in C++?
One of the reasons is that at the time these projects were initiated, Java was not fast enough, if it even existed. For example blink is a fork of project from late 90's and same is true for gecko. Java's performance became competitive in this domain only after Java 6, which is about 2006. Another reason is that graphic acceleration in higher-level languages tend to be sub-par. There are more reasons, but performance is not one of them (unless you go to the extremes like python which is just no or OCaml which doesn't support multicore).
In fintech, Java is commonly used, even in HFT where miliseconds (even microseconds, really) matter. Even haskell is getting common these days. And these are systems, not applications. The meme that you can't use a high-level language or garbage-collected language is just that, a meme. The only scenario where you would be handicapped by garbage-collector is when your system is fully specified in terms of memory management (very rare, aerospace comes to mind) or when you absolutely need deterministic performance (again, aerospace is the only domain that comes to mind).