News for hackers. Stuff that matters.
Re:C++ Frequently Questioned Answers (2009) by praptak on Sunday January 23, 2022 @06:27AM (#30045393)
The best C++ developers are those who violently oppose extending the subset of C++ features used in a project.

"Template specialization and traits? This belongs in library code. The resulting code is actually more bloated than the copy-pasted version. Nope."

Re:C++ Frequently Questioned Answers (2009) by protomolecule on Sunday January 23, 2022 @06:49AM (#30045500)
"The resulting code is actually more bloated than the copy-pasted version"

How is that possible?

Re:C++ Frequently Questioned Answers (2009) by ChrisLomont on Sunday January 23, 2022 @07:44AM (#30045752)
Templates expand, and can generate arbitrary amounts of code. If you, as a developer, don't see what happens, then you might miss it.

Templates can also expand on each type they use, or combination of types, generating much more code, when non-template solutions could have avoided it. Of course, templates could avoid it too, but they're much harder to write and see how they expand.

That said, templates also allow making code shorter and cleaner.

So some people, once bitten by bad templates or bad usage, complain without learning how to use them. Yet another C++ ocean of complexity :)

Re:C++ Frequently Questioned Answers (2009) by praptak on Tuesday January 25, 2022 @04:34AM (#30069991)
It is possible with every kind of de-duplicating copy-pasted code. You need some boilerplate for the common template (not necessarily in the C++ sense), then some more boilerplate for its instantiations to replace the previously-copypasted blocks of code.

Then the blocks weren't exactly identical, so the template (again, not necessarily C++) needs to gain placeholders/ifs and the instantiations need to fill them/provide conditions.

If you do it with C++ templates using the traits machinery, it generates quite a lot of bloat. It is not a reason to never use these mechanisms, just to be wary of the costs.

Re:C++ Frequently Questioned Answers (2009) by protomolecule on Tuesday January 25, 2022 @05:03PM (#30078758)
"If you do it with C++ templates using the traits machinery, it generates quite a lot of bloat. "

That's exactly the part that I don't understand. How does using traits machinery generate more bloat than some other way to de-duplicate the same code? And what kind of bloat do you have in mind -- source code or binary?

Re:C++ Frequently Questioned Answers (2009) by turminal on Sunday January 23, 2022 @06:59AM (#30045540)
More bloated != more lines of code
Re:C++ Frequently Questioned Answers (2009) by protomolecule on Tuesday January 25, 2022 @05:07PM (#30078801)
Unless you mean 'More complicated != more lines of code' I don't understand you.
Re:C++ Frequently Questioned Answers (2009) by bsenftner on Sunday January 23, 2022 @07:09AM (#30045575)
Been a C/C++ daily user for 40+ years. The key to being great is to ignore much of what is possible in C++'s templating and just write C code, and only borrowing C++'s highest level OOP class structures. One gains the organization of OOP and faces none of the template nonsense "mature" C++ developers get hung up trying to achieve. Template only when no other method makes sense, and do so cautiously. Why? Because template metaprogramming is simply too error prone, and the time to debug that is less than the hassle of doing the same without templates.
Re:C++ Frequently Questioned Answers (2009) by ncmncm on Sunday January 23, 2022 @06:34PM (#30051806)
It is easy to find people like bsenftner who have elected to stop learning, and to continue writing in an old, crappy, error-prone style. They are not representative of competent C++ coders.

For the record, OOP is a bad fit for most problems. The overwhelming majority of actual template use has nothing to do with "template metaprogramming", which has been superseded by modern language features he evidently knows nothing about.

Re:C++ Frequently Questioned Answers (2009) by bsenftner on Monday January 24, 2022 @12:15AM (#30053964)
Easy cheap shot. Who says anyone stopped learning? Coding is not the goal, which the vast majority of developers seem to not realize. The goal is the minimal technology necessary to impact the physical world here. Lay down the latest buzz words, pick up the known tools and get the job done. Look past the technology and critically assess how to impact the world. You may see "old, crappy error prone style" while the greybeards see familiarity and understand what is happening without mental gymnastics, understand the code base in a fraction of the time, and deliver evergreen, fault tolerance processes with exponentially less expense to maintain and operate. While you're busy writing the latest resume jerk off, I'm implementing industry leading enterprise applications and acquiring global patents.
Re:C++ Frequently Questioned Answers (2009) by ncmncm on Monday January 24, 2022 @01:35AM (#30054298)
I am a greybeard who has not abandoned learning new things.

Modern features in C++ are not there to pad resumes. Each is carefully selected from a much larger number of proposals as demonstrating it enables writing cleaner, clearer, more reliable, faster code. If you choose not to use any of them, you are perforce choosing to write less clean, less clear, less reliable, slower code.

Re:C++ Frequently Questioned Answers (2009) by bsenftner on Monday January 24, 2022 @08:25AM (#30057292)
What is this aggressive "abandoning learning new things" label? My teams choose a method of C++ that does not include deep hierarchies and shuns generic programming via overuse of templates. Beyond that, we focus on the purpose of the software, as it why are we here and how do we solve this within a sustainable and minimal expense frame. As far as "less clean, less clear, less reliable, slower code" - you are a complete and utter fool to believe such fantasies. Those points are why I and my teams write code as we do: it is clean, clearer, more reliable, and exponentially faster.

And the sheer audacity to think only your method produces such results. Grow up.

Re:C++ Frequently Questioned Answers (2009) by ncmncm on Monday January 24, 2022 @06:43PM (#30065780)
That you mention "deep hierarchies" as something you evidently imagine must exist in others' code reveals all.
Re:C++ Frequently Questioned Answers (2009) by bsenftner on Tuesday January 25, 2022 @04:13PM (#30078113)
You project a lot.
Re:C++ Frequently Questioned Answers (2009) by aaaaaaaaaaab on Sunday January 23, 2022 @06:41AM (#30045461)
This kind of restraint and level-headedness is the most important trait of a senior developer. The industry sorely needs more of them, not just in C++…