Easy C++ Questions

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

No, C++ is faster in nearly all respects if used correctly. Just like C is only faster when used "correctly". For example the Linux kernel is without a doubt best implemented in C due to C++ functionality (templates, virtual functions, objects) adding needless overhead to the code.

You also need to consider "fast" in terms of difficulty of implementation. C++ can include C-like code in inner loops where needed which executes exactly as fast as in pure C. At the same time these inner loops can be implemented as a part of objects including templates, functors, virtual functions, namespaces, hierarchy and so forth as required to make life easier for the programmer as well as reduce the potential for bugs via instrumentation as in my example code posted above.

C++ is a far more complex language miles above pure C which requires a far more experienced and capable programmer. It opens up plenty of opportunities for the programmer to shoot themselves in the foot - as if C didn't already - if the programmer is an idiot.

"In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg." — Bjarne Stroustrup.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

aciddose wrote:No, C++ is faster in nearly all respects if used correctly.
Thanks. I needed a good laugh. :lol:

People state this becuase they are comparing a C++ program using one of the STL algorithms (which are very good and highly optimized) to poorly written, non-optimized code written in C. The truth is, and I stated this earlier, languages are not fast, code is. The underlying code in the supporting libraries is what is fast or slow. It all compiles down to assembly code eventually, at least for non-interpreted languages.
aciddose wrote: Just like C is only faster when used "correctly". For example the Linux kernel is without a doubt best implemented in C due to C++ functionality (templates, virtual functions, objects) adding needless overhead to the code.
Additionally, kernels need to be small and optimal. There is no room for huge run-time libraries.
aciddose wrote:You also need to consider "fast" in terms of difficulty of implementation. C++ can include C-like code in inner loops where needed which executes exactly as fast as in pure C. At the same time these inner loops can be implemented as a part of objects including templates, functors, virtual functions, namespaces, hierarchy and so forth as required to make life easier for the programmer as well as reduce the potential for bugs via instrumentation as in my example code posted above.
Agreed. Even assembly can be included in time critical loops. Both in C and C++.
aciddose wrote:C++ is a far more complex language miles above pure C which requires a far more experienced and capable programmer. It opens up plenty of opportunities for the programmer to shoot themselves in the foot - as if C didn't already - if the programmer is an idiot.
I disagree, but only in a technical sense. C++ is barely more complex than C. The libraries that make C++ so useful are what also makes it complex. But you are right, in that it can be much harder to learn, and even harder to master.
aciddose wrote:"In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg." — Bjarne Stroustrup.
You gotta love the compiler errors from C++. All that complexity is spewed forth in a multi-page error message because of one small syntactical error. :)

Post

Did you not understand my post at all? That's how it seems based upon the content of your reply.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

aciddose wrote:Did you not understand my post at all? That's how it seems based upon the content of your reply.
I think I did, and agree with much of what you wrote. It did not offend me, and I was not attempting to offend you either. I did take issue with the blanket statement that C++ is faster when used properly. That is simply not true, and I attempted to point that out. I also respond similarly when people make statements that language X is faster than language Y. I can find case where Python is faster than C, C is faster than Java, Java faster than C, etc.

We can compare this discussion to a determining the best guitar. There is no write or wrong answer, and in most cases (including the language debate), the best improvements can be found by perfecting ones use of the available tools, not by acquiring new ones.

With that said, I feel some GAS coming on. I need to take advantage of some Black Friday sales and get some new VSTs so I can make better music. :D

Post

So no, you are totally clueless about what I intended to convey. I don't think I can explain it, I'm sorry. I can only say you're totally off base.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

OK. You win. I'm clueless. C++ programmers are superior beings who must be worshiped for their vast skills in tackling such a complex language. I bow before your superiority. :wink:

Post

Ciberithm wrote:I also respond similarly when people make statements that language X is faster than language Y. I can find case where Python is faster than C, C is faster than Java, Java faster than C, etc.
Coding time in some languages is surely faster than C, so I find these languages faster as well :)

Post

Ciberithm wrote:OK. You win. I'm clueless. C++ programmers are superior beings who must be worshiped for their vast skills in tackling such a complex language. I bow before your superiority. :wink:
Still totally off base. This very sort of statement is what proves you don't understand.

Spend the next ten years writing purely C++ code. Write a professional application with zero bugs reported in beta and one or two you notice and fix yourself months or years after release. Then we will discuss the definition of "faster".

Image

Come across to the dark side.

You'll never know what lies in the shadows under the stones you never lift and peer below.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

Ciberithm wrote:My statement was not meant to be taken seriously - note the smiley face. :roll:
Sorry, I didn't understand it that way, probably because I should have taken an additional minute before replying ;)

Post

C++ is barely more complex than C
Some people can't get their heads around templates or even inheritance and there is a LOT that can be done with it. In fact this is where all magic happens.
Not to mention new C++11/14 features, such as lambdas, move semantics and more. I can't even see how you want to back up the idea of C being as complex as C++.
Blog ------------- YouTube channel
Tricky-Loops wrote: (...)someone like Armin van Buuren who claims to make a track in half an hour and all his songs sound somewhat boring(...)

Post

But these are the layers (mainly templates) that can make code smaller and faster (to write and to execute), so it is a trade-off.
In HPC applications, when you try to achieve the maximum performance but at the same time maximize maintenability, I think you need to use a language that gives you this level of control.

Post

A good language should allow "simple" code changes. I find C to be the worst in this aspect, at least with regards to how much change is made with a few keystrokes.

Post

Very well written code in C can be maintainable.

The problem is when you get dumb-asses telling you C is both faster and easier to write creating horribly buggy code that barely manages to maintain a balance on the edge of a razor blade. A tiny change like a soft breeze and suddenly guts are strewn across the floor.

It's just like any language though. The vast majority of code written was written by amateurs or pseudo-experts. Just look at the comments on the Linux kernel mailing lists about the absolute shit that gets added to pull requests. You can see Linus and others blow up about it or other bullshit regularly.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

Nowadays I code most of time in c++
It's not bad, if you created a proper framework you can avoid most of mistakes.
But.
But.
Each time I grab a java project again (our back-end server) I feel like I'm in heaven again. Such a pleasure!!! Totally relaxed. I can even code with loud music playing from my loudspeaker. Everything I try works!!!! Difficult to explain.

C++ compiling time - in large projects drives me crazy. Yes you need to work a lot on precompiled code, but still it is never optimal. And each time you compile there is a warning. An error. A crash. Java is seriously simple.

Post

Chris-S wrote:
DJ Warmonger wrote:Don't use smart pointers for low-level DSP, though, they add performance penalty.
They add only a small performance penalty.

https://msdn.microsoft.com/en-us/library/hh279674.aspx
Agreed.
Use smart pointers. Smart everything. Always. For critical stuff just avoid to allocate and free there

Post Reply

Return to “DSP and Plugin Development”