Re: We do not use C++ exceptions
On Jan 14, 12:36 pm, Mathias Gaunard <loufo...@gmail.com> wrote:
On 14 jan, 01:23, Le Chaud Lapin <jaibudu...@gmail.com> wrote:
if (arg < 0)
perror ("Negative value passed to function when positive value
expected!!!"); // silly, IMO :)
They simply don't know about assert(arg >= 0).
Making arg unsigned could also have been a solution (or not).
I think it is. This goes along with the philosophy that part of being
a good engineer is structuring the system so that certain awkward
questions never need be asked:
Q: What happens when value of this inherently positve argument is
negative? Should I assert?
A: You should not have declared it int. Make it unsigned int.
Q: How do I return an error code from a constructor if exceptions are
not available:
A: You should use exceptions.
Q: 80% of my classes are abstract. I get lost in memory management?
What should I do?
A: Ease up off the polymorphism, dude! Try a little concrete for
change. Have a map<> or a set<>.
Q: I like new(). I like it so much that I new() concrete objects that
could just as well have not been auto constructed. Should I auto_ptr<>
the returned pointer to help with memory managment?
A: Ease up off the new().
Q: My 2-month old new and fancy universal deep-copy framework is not
quite right though I have exerted Hurculean effort to make it such.
What should I do?
A: Rethink the very notion of "deep copy".
Q: My 2-month old new and fancy C++ introspection framework will not
automate itself. I just know I am missing something because it happens
all the time in Java. Why won't these classes instrospect themselves?
Is C++ defective?
A: C++ is not Java or any other interpreter-assisted language. Think
very carefully about comparing C++ to something that is fundamentally
different from it. If you insist, define an object that is a
hierarchy, where each node of the hierarchy is a mapping of string to
an associative set of string to string. That's the best you're going
to get in C++.
-Le Chaud Lapin-
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]