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

Need help with C, C++, perl, python, etc?

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

Postby neuraleskimo » 2019-04-23 14:32

MagicPoulp wrote:The apache httpd webserver is in C++. nginx is in C. The latter wins all the benchmarks. And this is because it has no overhead from object-oriented rules.

No. You can't make sweeping generalizations like that. There are so many issues (e.g., algorithms or threading) that go into benchmarking whole applications that you can't pin it all on the difference between C and C++. I don't want aspiring programmers to read this chain and think "I picked the uber language, so my code is as fast as it could be!" No. Just, no.

I have consistently suggested resources and tools that will help you address your concerns. The reason people write C/C++ as if they are interchangeable is that C++ programmers will select from pure C techniques, generic algorithms, static polymorphism, dynamic polymorphism, etc. as needed. For most, this is not some religious issue. The difference between C and C++ is extremely small for most cases. What I want to encourage aspiring programmers to do is pick the right techniques for the problem. The key is to use the tools I suggested (e.g., Compiler Explorer) and a good benchmarking library (Google Benchmark is pretty good). Also, watch the many, many excellent C/C++ conference talks on YouTube.

[Edit:] By the way, one advantage of nginx is a better architecture. Mainly, queueing to make better use of threads.
User avatar
neuraleskimo
 
Posts: 102
Joined: 2019-03-12 23:26
Location: Bloomington, Indiana, USA

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

Postby MagicPoulp » 2019-04-24 07:55

In my quote I wanted to say nginx wins all the benchmarks, which is 100% true. I did not want to mean that C wins all the benchmarks. In the stack overflow link I said, people can vote on best answers, and the consensus is that it depends and that both C and C++ can have good performance.

But I really think optimizing C++ requires much more skills.

But the comparison GNome vs KDE is interesting I think. The language affects the result.
MagicPoulp
 
Posts: 197
Joined: 2018-11-05 21:30

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

Postby Head_on_a_Stick » 2019-04-24 16:47

Both gcc and clang are written in C++ so I think the battle's lost anyway...

Disclaimer: I'm not a programmer so I don't really know what I'm talking about :mrgreen:

EDIT: golang ftw!
User avatar
Head_on_a_Stick
 
Posts: 10346
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby neuraleskimo » 2019-04-24 17:00

Head_on_a_Stick wrote:Both gcc and clang are written in C++ so I think the battle's lost anyway...

LOL! You nailed it Head_on_a_Stick. I hadn't thought about it, but... Java is written in C++ and Python in C. Clearly, that explains everything! :wink:
User avatar
neuraleskimo
 
Posts: 102
Joined: 2019-03-12 23:26
Location: Bloomington, Indiana, USA

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

Postby pylkko » 2019-04-24 17:41

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?)
User avatar
pylkko
 
Posts: 1526
Joined: 2014-11-06 19:02

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

Postby neuraleskimo » 2019-04-24 18:12

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...
User avatar
neuraleskimo
 
Posts: 102
Joined: 2019-03-12 23:26
Location: Bloomington, Indiana, USA

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

Postby neuraleskimo » 2019-04-24 23:45

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.
User avatar
neuraleskimo
 
Posts: 102
Joined: 2019-03-12 23:26
Location: Bloomington, Indiana, USA

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

Postby MagicPoulp » 2019-04-25 08:07

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.
MagicPoulp
 
Posts: 197
Joined: 2018-11-05 21:30

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

Postby cronoik » 2019-04-25 12:17

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!
cronoik
 
Posts: 308
Joined: 2015-05-20 21:17

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

Postby MagicPoulp » 2019-04-25 14:53

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)
MagicPoulp
 
Posts: 197
Joined: 2018-11-05 21:30

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

Postby cronoik » 2019-04-25 15:22

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!
cronoik
 
Posts: 308
Joined: 2015-05-20 21:17

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

Postby MagicPoulp » 2019-04-26 09:52

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.
MagicPoulp
 
Posts: 197
Joined: 2018-11-05 21:30

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

Postby neuraleskimo » 2019-04-26 12:33

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.
User avatar
neuraleskimo
 
Posts: 102
Joined: 2019-03-12 23:26
Location: Bloomington, Indiana, USA

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

Postby MagicPoulp » 2019-04-26 14:08

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.
MagicPoulp
 
Posts: 197
Joined: 2018-11-05 21:30

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

Postby neuraleskimo » 2019-04-26 14:14

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!
User avatar
neuraleskimo
 
Posts: 102
Joined: 2019-03-12 23:26
Location: Bloomington, Indiana, USA

PreviousNext

Return to Programming

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable