Quote:Original post by SiCrane
Quote:Original post by doynax
Even a beginner should feel free to use leading underscores if he think's that makes the code easier to read (or "prettier") and is prepared to deal with the issues that might come up. The important thing to note is that it's a rare occurance but can be hard to analyze when it's happens, especially if you're not experienced to C++.
There's no reason to suggest to a beginner that he get used to this coding style to start with. That's just bad advice. So what if you've never had a problem with it? The fact that the issues are rare make it even more important to avoid this kind of crappy coding practice to begin with; by the time someone does run into a problem with it, he may have forgotten that there's an issue with this kind of practice. (Another good reason to mention it whenever appropriate.) The fact of the matter is that people do run into these problems. I've had them, other people who've posted on these boards have had them and people I've worked with have had them.
Yes, but I've never recommended anything one way or the other. I mostly try to stay away from coding style debates entirely.
All I'm saying is that it's never been such a big issue, and I want people to be able to make an informed decision about it rather than hearing "it's evil, stay away". Just beware of the risks and choose for yourself.
Besides, I still think you're considerably more likely to collide with another library than a reserved identifier in the compiler. So I'm quite sure I've got fewer collisions nowadays compared to (one of) my previous styles without the leading underscores or any prefix/postfix at all.
Quote:Original post by SiCrane
Quote:In general renaming identifiers is a good trick to use when you've got a seemingly bizzare bug to fix.
Ah yes, the school of voodoo programming where you try random changes to your code to silence symptoms without understanding what the real problem is. Here's an idea: don't use a coding style that allows these kinds of problems in the first place.
You can't get away from this kind of thing in C++, sooner or later something "weird" happens and you've got to deal with it.
You still have to analyze the issue of course, but the first step towards finding the cause of this particular class of bug is figuring out if there's something strange going on with your identifiers.
Quote:Original post by SiCrane
Quote:Thus I judge that it's worth it (for me).
Fine, you accept that you have a bad habit. Don't try giving it to others.
*Groan*
Just about everything is bad to one degree or another. Try to make informed decisions and use it right, that's all there is to it. This has never been a matter of absolutes.
What you should ask yourself is if it's the style that you find easiest to read and write. And, if so, if you're prepared (and experienced enough) to deal with a few bizarre bugs if they come up. Also beware that this is another portability when switching compilers (although that's rarely pain-free however carefully you code). Thus the rewards are greater than the risks then I say use it, but for beginners it almost certainly isn't.
Quote:Original post by rip-off
Quote:
In general renaming identifiers is a good trick to use when you've got a seemingly bizzare bug to fix.
okay, your style is your own, and i cant stop you using it. but this is the best bit of advice you've given yet. because thats what every programmer does when they've got a bug to fix. out of curiousity how often does this actually work for you? how often does it create even more bugs?
It works fairly often actually, often it's an overloaded macro that does unexpected things to your code. But most of the time I just use it to rule out this class of bugs.
As I said above it's just another trick coders use to locate bugs, you still want to find the source. The next step may be #define the identifier to see if there's any macros covering it, or googling to see if it's a known identifier.
I suppose the min() and max() macros from Windows.h is a good example here.
[Edited by - doynax on January 7, 2006 11:17:25 AM]