Common notation

Started by
39 comments, last by SiCrane 18 years, 3 months ago
Quote:Original post by doynax
That's like arguing that hungarian notation is as good as any other naming convention because you can become familiar with it.

Incorrect generalization. It's a supporting argument against, not an argument for, and cannot be applied as an argument for. To apply the same argument in the case of Hungarian, you would have to say that there are other naming conventions that are just as easy to read that lack Hungarians disadvantages.

Quote:You're right and that's a good technical example. Why didn't you say so to begin with? ;)

For one thing, I shouldn't have to. Reserved for any purpose means the identifiers are reserved, and using them is bad mojo in and of itself. Secondly, it's somewhat unsporting to pick on obsolete compilers; MSVC 6 will C1001 if you accidently use a : instead of a ; in the right(wrong) spot. No one should be using MSVC 6 or 7 anymore. With the toolkit released, you can use the 7.1 compiler in place of the 7 compiler even if you only have the 7 IDE, and there's just not much reason to use a brain dead compiler like MSVC 6 with other, better and free alternatives available.

Quote:Is this likely to cause anything beyond compiler crashes? In most cases I guess these would be shielded within the std namespace or overloaded when inheriting from a template class.

Not all of them are shielded in the std namespace. MSVC for example defines a lot of function with a single underscore prefix in the global namespace and a few types.

Quote:I primarily use VC6 and I can't find a way to get a direct list of defined symbols from it, so I guess it's what you'd call a brain dead compiler. Anyway you can always invoke it separately and look at the output for much the same effect (I tend to use it to debug complex macro hacks, boost pp-ish things).

Try running the cpp program from the gcc toolchain with the -dM options instead. It will give you a list of all the symbols defined.

Quote:But changing the compiler settings and finding the appropriate output file or dropping out to the command line and hope you've got the right environment macros defined takes me a lot of time. Redefining or renaming the symbol and recompiling takes almost none, especially since I most often use it just to be able to eliminate that class of bugs.

This is why I have my windows shell configured so I can open a bash prompt at any directory with all the proper environment variables set with a right click and context menu selection. If you work on large projects it's often a lot faster to run the preprocessor like this than it is to run the compiler. (Especially of some bastard working on your team decided that template metaprogramming is the best thing since sliced bread. Not that I'm bitter or anything.)

Quote:The whole point of that quote is obviously to put things into perspective. I say that while _foo is technically bad, there are much worse things out there.

You failed at making that point. It comes across as saying there's nothing wrong with leading underscore naming conventions with a touch of a perscution complex attached. And no one here has said that you shouldn't use a naming standard. The entire point is to chose one that works. Yours doesn't. You've just been lucky that you haven't run into any problems yet.

Quote:Most of all I'm trying to tell those who may be about to abandon the style because it's "evil" that they may not have heard the whole story, and that the supposed problems seem to have been exaggerated. Look deeper into the advantages and disavantages and judge for yourself.

And you're not doing anyone any favors by spreading this kind of misinformation. It is a bad practice, and people have lost weekends debugging problems that could have been avoided just by following a naming convention that didn't ignore basic rules of the language.

Quote:A bizarre and annoying problem would rather be something silent, consider something truly nasty like inadvertantly changing the alignment of a variable.
Like, I don't know, pulling in a defintion of _complex that uses double values instead one you've defined yourself that uses floats? Could happen if you use the math header in MSVC. Or how about accidently using an _exception class that has a few more members than you expect? With MSVC, the right using declarations and some namespace magic, that's a possibility too. And since you've decided to interoperate with C, just imagine when that comes together at link time if you pulled one version of the type in one translation unit and another version of the type in another translation unit, and the linker is silent because you've wrapped those suckers in a extern "C" so the name mangling on functions is disabled. Caller calls the version expecting class layout A, callee interprets pointer as layout B and you've got a nice buffer overrun in the works. Runtime flags it as heap corruption and you spend your time checking the bounds on all your loops instead of examining the possiblilty that you got a type violation on your hands.

Quote:
Length (that is overhead) is easily and objectively quantifyable, so we're basically left with the alternative of using a trailing underscore instead.
I read from left to right, I sort from left to right (for identifiers anyway), I compose hierarchies from left to right, I line up code from left to right, etc. It's hardly surprising that I perceive a prefix as more significant than a postfix. At least that's my technical explanation.

There are also case differences. For example LikeThis for public and likeThis for private. It's shorter than your style; and the significant discriminator comes at the front. You could also prefix all internal names with something like Z, X or Q. Same length as your style, violates no rules and still uses a significant prefix.

Quote:
But more importantly for me personally is that I tried it out and never got as comfortable with it as the prefix-based naming conventions.

Fine. Again, you can use whatever you want in your projects. But for people who haven't gotten use to any standard yet, you shouldn't be trying to push a defective naming convention. And I'm sorry, it still comes off like you are trying to push your style.

This topic is closed to new replies.

Advertisement