Why do people and companies use more C++ than C?

Programming languages, Coding, executables, and scripting.
Message
Author
neuraleskimo
Posts: 195
Joined: 2019-03-12 23:26

Re: Why do people and companies use more C++ than C?

#21 Post by neuraleskimo »

pylkko wrote:not a programmer, but what do you mean? like that python interpreters and the whatever "java virtual machine" are written in c++?

because isn't a programming language specification written in a natural langauge (english?)
Ah, very good question. I was a little loose with my language. Yes, the language specification is written in English. However, the tools must be written in some programming language. Most compilers, interpreters, etc. are written in C or C++. That may change with time if Rust, etc. gain more traction. The java compiler (that converts Java code to Java bytecode), virtual machine (a.k.a., Java VM), and associated tools are written in C++. The Python interpreter (CPython at-least) is written in C.

Hope that helps...
Black Lives Matter

neuraleskimo
Posts: 195
Joined: 2019-03-12 23:26

Re: Why do people and companies use more C++ than C?

#22 Post by neuraleskimo »

I don't want to be too hard on MagicPoulp, but he/she needs to give-up on the language religion. There is no perfect language. Languages are tools with strengths and weaknesses. I have watched generation after generation of students struggle with choosing a language to hang their career on. For some, the search for that perfect language is all consuming. This is why this topic matters to me.

My advice over the years has changed slightly with the times, but in general, pick any one of the top five or so languages. It really doesn't matter. Pick one that "speaks" to you: one that excites you, one that is comfortable, one that make sense, ... What matters more than the language? Learn whatever language you pick WELL! Very, very well!

Most languages allow you to write code using several styles/techniques (e.g., functional programming, generic programming, or OOP). Each of those techniques is a tool that has ideal use-cases. Learn those well. Learn to apply them correctly. The first key to unlocking performance and elegant solutions is about understanding when to apply a given technique. Use the right tool for the job. Then learn how/when to use good algorithms written by experts. This is the second key to writing fast and elegant code. Frankly, the only bug-free code you and I will ever write is the code we don't write. Next, learn how to write good algorithms using each of those techniques. This is the third key to writing fast and elegant code. Put another way, clever code usually is not. Especially, when you are trying to fix a bug six months later.

Once you have done all of the above for one language, learn another in exactly the same way.

One parting thought... I saw a conference talk where the (very well respected speaker) asked the audience what percentage of their code was performance critical. Obviously, most of the audience raised their hands for "most" of their code. Then the speaker asked the audience for how much of their code have they written benchmarks. Obviously, most of the audience only wrote benchmarks for a small part of their code. Then he said that if you do not have benchmarks, you can't/don't care about performance. Writing entire programs in Python, for example, is perfectly fine. Using Python, for example, as the glue between performance sensitive code written in C/C++ is also perfectly fine. I have written code in C/C++ for a large portion of my life; however, I am a huge fan of shell scripts and Python. Using shell scripts to glue together chucks of C/C++ code is the (ancient and current) UNIX/Linux way. For some reason, we tend to forget that.
Black Lives Matter

MagicPoulp
Posts: 426
Joined: 2018-11-05 21:30

Re: Why do people and companies use more C++ than C?

#23 Post by MagicPoulp »

I did not know that Java was written in C++. I checked and it is correct. I had to check after the many rumors that C libraries are written in C++. Java has a bad reputation for performance and overgrowth in memory. ANd actually the OOP structure of C++ may contribute to it. THink about it. Exceptions take memory than return codes. Virtual funtions have a performance impact. Etc. It is not because of C++. It is because of how C++ was used.

But it is true that C++ has very good use cases. Medical software that must not fail are often in C++. One should not pick C in that case.

cronoik
Posts: 310
Joined: 2015-05-20 21:17

Re: Why do people and companies use more C++ than C?

#24 Post by cronoik »

MagicPoulp wrote:But plain old C would work just fine in many cases. Nowadays, I don't think any commercial project would use C unless the hardware requires it or the developers actively prefer C. Open source projects still use C quite a lot. Examples: nginx, gnome, etc.
The reason is often much simpler. When your company has a bunch of developers with C++ experience why should you force them to C? It will just reduce the quality of code and increase the costs. Maybe when you write the program in C it will be a little bit faster as when you use C++, but how often does the performance really matter? Rarely. In case it matters it is often cheaper to buy better hardware compared to hiring an expert for an certain language. Another reason could be security. Take a look at this survey [1] which shows us that their is a huge difference between "I'm able to write programs in C" and "I'm able to write good (i.e. performance, readablity, secure) C programs".

[1] https://www.techrepublic.com/article/th ... languages/
Have a nice day!

MagicPoulp
Posts: 426
Joined: 2018-11-05 21:30

Re: Why do people and companies use more C++ than C?

#25 Post by MagicPoulp »

But they already chose C++ over other (Python, Java) because they think C++ is faster. And they believe C++ is faster and safer than C for theoretical reasons.

I think most companies that don't pick C++ for performance, will quickly move to Python, Java, C#, etc. This is how the managers think. SO they can skip header files totally, etc. But developers will prefer C++ for obvious reasons. That they have more experience is just a marketing argument.

Games are obviously in C++ for being safer due to so many quality problems in games. But they want performance.

I think most people think C++ has OOP and C has not OOP due to the class word missing. As someone said here earlier. Even though there are ways to make OOP in C, it is not standard. OOP requires more than just the class keyword. It needs public, private, inheritance, etc. And the GObject framework in C that has the same features is not very intuitive.

Here is to have a private variable:
G_DEFINE_TYPE_WITH_PRIVATE (MyAppLabel, my_app_label, GTK_TYPE_APPLICATION_LABEL)

cronoik
Posts: 310
Joined: 2015-05-20 21:17

Re: Why do people and companies use more C++ than C?

#26 Post by cronoik »

MagicPoulp wrote:But developers will prefer C++ for obvious reasons.
Would you consider data scientist as developers? Do you think really think they like Python and R due to marketing arguments or because their managers have forced them to use it? And how about Apache Hadoop or Apache Spark do you think is was written in Java/Scala because of a management decision and not due to a decision of the initial developers?
MagicPoulp wrote:Games are obviously in C++ for being safer due to so many quality problems in games. But they want performance.
What is your explaination for Unity? It doesn't offer a C++ API but a C# API.

Actually I do not understand what kind of point you are trying to make. You have asked us why some companies choose C++ instead of C and a plenty of developers and admins gave you valid reason why this could be the case. Most of the top managers don't care about the programming language. For them it is important that they get the job done and the costs are under control.
Have a nice day!

MagicPoulp
Posts: 426
Joined: 2018-11-05 21:30

Re: Why do people and companies use more C++ than C?

#27 Post by MagicPoulp »

I say "Games are obviously in C++." And you come and say ah stop not 100%.

Ambitious games do not us C# and Unity. That does not mean there cannot be good games in Unity. Besides I was comparing C and C++ for games.

https://www.quora.com/Can-you-make-Trip ... sing-Unity

It is quite obvious that most developers would prefer C++ over Java or C#. But I don't think it is interesting to debate this. I just think it is a fact that Java and C# are the most wanted competencies.

This is a problem of logic. If here is a trend around Java and C#, does not mean one can generalize 100%, and that technologies built on Java would have been forced by managers.

And where is the point? Well many projects that take C++ as if it was evident did not consider enough C as an alternative.

neuraleskimo
Posts: 195
Joined: 2019-03-12 23:26

Re: Why do people and companies use more C++ than C?

#28 Post by neuraleskimo »

MagicPoulp wrote:And where is the point? Well many projects that take C++ as if it was evident did not consider enough C as an alternative.
I don't know how many different ways we have to say it: choosing C++ gives a programmer the entire C toolbox and more! They did not reject C. They choose the bigger toolbox of ready-made zero/low-cost abstractions and moved on with their lives.
Black Lives Matter

MagicPoulp
Posts: 426
Joined: 2018-11-05 21:30

Re: Why do people and companies use more C++ than C?

#29 Post by MagicPoulp »

Counter example.

In terms of computer science, C is almost a subset of C++. I say almost because not 100%. It will be libstdc++ that will run the C code.

Here is the counter example. In practice, most C++ style guides, will forbid many features of C, in particular the macros to define constants.

neuraleskimo
Posts: 195
Joined: 2019-03-12 23:26

Re: Why do people and companies use more C++ than C?

#30 Post by neuraleskimo »

MagicPoulp wrote:Here is the counter example. In practice, most C++ style guides, will forbid many features of C, in particular the macros to define constants.
Because C++ provides abstractions that are zero-cost and safer. I have already said that in this thread! I also gave you sample code and pointed you to Compiler Explorer to verify that EXACT point! What the *!@&# dude!
Black Lives Matter

larienna
Posts: 64
Joined: 2014-09-27 20:54

Re: Why do people and companies use more C++ than C?

#31 Post by larienna »

I am still surprised that C++ is still the dominant language. From my point of view, I think the reason why people still use C++ is because it's object oriented and a lot of C++ code has already been made so far, so it requires maintenance. I think that C# will eventually replace C++ because at least it has a garbage collector which makes OOP less a pain.

I followed a few years ago a new class of plain C and I fall in love again with the language. All my hatred of C was in fact due to C++. Yes it is a more dangerous language because you have complete control on the the system. And you need such control for writing low level code (Drivers, OS, etc). Doing the same in C++ is possible but very risky.

An interesting quote that I found on the net was that: "C++ makes it harder to shoot yourself in the foot than with C, but when you do shoot yourself in the foot with C++, it's the whole leg that blows up"

giaur
Posts: 120
Joined: 2013-03-08 07:03

Re: Why do people and companies use more C++ than C?

#32 Post by giaur »

Wrong question. For some tasks C performs better, C++ is reasonable for other tasks. It depends

Btw, C# will never replace C++, the same as motorcyles will never replace cars - both are used for different tasks.

DebbyIan
Posts: 157
Joined: 2013-05-09 12:12

Re: Why do people and companies use more C++ than C?

#33 Post by DebbyIan »

C has fewer concepts but is harder to use "correctly".


C++ is more strongly typed and as such it's less susceptible to mistakes being carried forwards of the compilation process. Never underestimate the level of type specificity in a language, especially when it comes to C or C++.


If you're going to learn to use C properly you'll end up using it in a C++ style.

Post Reply