Question regarding deleting pointers to matrices

Started by
16 comments, last by Zahlman 17 years ago
Quote:Original post by Bregma

I would argue you're not practicing low-level C++ programming, you're practicing low-level C programming.

If you wanted to be programming in C++, you would be using std::valarray for this stuff. If you really wanted to be doing low-level C++ programming, you would be specializing std::valarray.

--smw


and I would argue that since "new" and "delete" aren't C that his code is distinctly C++.
Advertisement
Quote:Original post by linternet
and I would argue that since "new" isn't C that his code is distinctly C++.


He uses "new" instead of "malloc" and "delete" instead of "free". Hardly deserving of a distinctly epithet, if you ask me. In fact, what he wrote is C code which requires a C++ compiler to compile. Just like IOCCC entries are not representative of a sane C program.
Quote:Original post by ToohrVyk
He uses "new" instead of "malloc" and "delete" instead of "free". Hardly deserving of a distinctly epithet, if you ask me. In fact, what he wrote is C code which requires a C++ compiler to compile. Just like IOCCC entries are not representative of a sane C program.


Point taken. I just don't understand why the community constantly denigrates perfectly legal, working code simply because it doesn't adhere to the academic dogma of a language.
Quote:Original post by linternet
Quote:Original post by ToohrVyk
He uses "new" instead of "malloc" and "delete" instead of "free". Hardly deserving of a distinctly epithet, if you ask me. In fact, what he wrote is C code which requires a C++ compiler to compile. Just like IOCCC entries are not representative of a sane C program.


Point taken. I just don't understand why the community constantly denigrates perfectly legal, working code simply because it doesn't adhere to the academic dogma of a language.


Because it can create silly situations. Consider a 100KLOC project written in C, but C++-compilable, with a header file included almost everywhere. Add an #include <vector> at the top of that one header file. The one hundred thousand lines of C code have automagically turned into C++.

Because of this, most people use the name "C++" to refer to modern C++, to distinguish it from C-compiled-as-C++. The main idea behind this is that (modern) C++ code is more easily exception-safe, interacts better with the standard library, requires less non-default constructors and destructors, and generally requires less work than the C-like version. It is not so much academic dogma as it is using the language to its full extent, doing less work to write faster and more easily maintainable programs.
Quote:Original post by ToohrVyk
Because it can create silly situations. Consider a 100KLOC project written in C, but C++-compilable, with a header file included almost everywhere. Add an #include <vector> at the top of that one header file. The one hundred thousand lines of C code have automagically turned into C++.

Because of this, most people use the name "C++" to refer to modern C++, to distinguish it from C-compiled-as-C++. The main idea behind this is that (modern) C++ code is more easily exception-safe, interacts better with the standard library, requires less non-default constructors and destructors, and generally requires less work than the C-like version. It is not so much academic dogma as it is using the language to its full extent, doing less work to write faster and more easily maintainable programs.


Understood and well explained.

The only thing I'll mention is that when working with old code and people whose skills are out of date (me) the practical application of purley modern C++ becomes nearly impossible.

I'm about as stubborn as they come and even I've seen the benefits of using std::string, and std::vector. If however(as a stupid example) I need faster-than-linear searching and am not quite ready to use std::map, I can put c_st()'s into a 10+ year old "C-style" hash class without losing the time it would take to figure map out.

That mixing is why a language that is (to use your signature) "an octopus made by nailing extra legs onto a dog" is so popular in the first place.
Quote:Original post by linternet
The only thing I'll mention is that when working with old code and people whose skills are out of date (me) the practical application of purley modern C++ becomes nearly impossible.


I agree. If all you know C, writing applications in modern C++ is a nigh impossible task, and a C++ compiler becomes little more than a C compiler upgrade.

Quote:That mixing is why a language that is (to use your signature) "an octopus made by nailing extra legs onto a dog" is so popular in the first place.


Quite sadly, yes, that's true. Sadly, few people realize that they're abandoning the simplicity of C without gaining the advantages of C++. The two languages, contrary to populary belief, interact together extremely badly.
Quote:
Quite sadly, yes, that's true. Sadly, few people realize that they're abandoning the simplicity of C without gaining the advantages of C++. The two languages, contrary to populary belief, interact together extremely badly.


You're basically saying that pre-standardized C++ is/was useless?
Quote:Original post by linternet
Quote:
Quite sadly, yes, that's true. Sadly, few people realize that they're abandoning the simplicity of C without gaining the advantages of C++. The two languages, contrary to populary belief, interact together extremely badly.


You're basically saying that pre-standardized C++ is/was useless?


It was a prototype, in many ways.

However, there were still advantages available to be gained - in particular, constructors and destructors for classes, and language support for polymorphism - that are only gained if you seek them.

This topic is closed to new replies.

Advertisement