3 ms·
I have a list of things to stay away from indeed, but it's due to my own sanity of being. For example, without GC exceptions are almost always going to cause l
by rpledge 17y ago
I have a list of things to stay away from indeed, but it's due to my own sanity of being. For example, without GC exceptions are almost always going to cause leaks without the team being all C++ experts. If I was designing in Java exceptions are wonderful, in C++, asking for issues
- jacquesm 17y ago> but it's due to my own sanity of being. I think that is what such lists have in common :) > For example, without GC exceptions are almost always going to cause leaks without the team being all C++ experts. That is something I rarely have had trouble with, but I never worked much in teams. I did notice that the double-free and never-freed pointers are a good portion of the problems you encounter in live code though. And every time firefox goes EWOL I'm fairly sure that somewhere deep down someones code just tried to reference a stale pointer or something like that. Even in Java exceptions are not all that wonderful, I think they are just a way to say "I don't feel like coding the stuff required to handle this situation properly, let's thrown an exception". You end up with more exception handling code sometimes than functional code and that isn't the right balance either.
- rpledge 17y agoThrowing an exception isn't saying "I don't feel like dealing with this", but rather, "A problem has occurred". In C++ (ignoring exceptions), you typically (or hopefully!) return an error code and rely on the caller to handle the issue. In Java, with checked exceptions, a catch or declaration that the current method can throw the same exception is needed for compilation. Now, this doesn't stop empty catch blocks or other horrible coding practices, but professional software engineers should never let that happen in their code (and there are lots of people who do, and they shouldn't be getting paid to write code!) Checked exceptions wouldn't fix the memory leak issues in C++, I routinely use the shared_ptr template to fix that, but it would be a good step forward.
- jacquesm 17y agoAye, I hear you. But the problem is not that people use stuff the way it is intended, but they will use it in ways that it is not intended! > Now, this doesn't stop empty catch blocks or other horrible coding practices, Exactly... > professional software engineers should never let that happen in their code I could show you some horror stuff I'm dealing with right now that does exactly that. The bigger problem is that it works and that I'm having a hard time convincing other people that that is not how it is done.
- dkarl 17y agoexceptions are almost always going to cause leaks without the team being all C++ experts Don't give up exceptions; give up naked pointers. Use shared_ptr and scoped_ptr, and you won't have memory leaks due to exceptions. Use RAII consistently, and you'll find it's actually easier to handle resource management in C++ than in Java. Java's resource management is superior for memory but inferior for every other resource.