Naming Convention Survey!
I'd appreciate anyone who has any opinion on this at all to throw in their 2c.
Part of my usual coding convention is that all type names should begin with a capital letter, and all object names should begin with a lowercase. This is largely due to coding in Java, but also due to coding in OCaml.
Specifically, this convention allows you to declare variables like this:
Foo foo;
"This code forms some sort of argument in that debate, but I'm not sure whether it's for or against." -- Tom Duff on Duff's Device, though I think it's also appropriate here to a lesser extent.


2 Comments:
This comment has been removed by a blog administrator.
(Previous comment deleted due to faulty logic.)
As I've mentioned before, I greatly dislike the fact that most languages are case-sensitive. There are a couple of reasons, one being that it introduces another way of causing bugs, namely trying to use the nonexistant variable happyFuntime instead of happyFunTime, for example. (As a side-note, happyFunTime should by default be initialized to the value of the constant SHIRTLESSOCLOCK.) This complaint of mine is (correctly, to be honest) often countered by saying that miscapitalizing things is just a specific case of a mistake that isn't a big deal, which is misspelling your names. However, this gets into the second reason: case-sensitivity encourages doing things like Foo foo;. You shouldn't have entities in your code with such similar names that misspelling one gets you into any more trouble than "nothing of that name exists".
I like the coding convention you've described, whether for a case-sensitive language or not, as it allows at-a-glance identification of whether something is a variableName, TypeName, or a CONSTANTNAME (to include another example from my own coding convention). But having both Foo and foo in your code is 1) asking for trouble just as badly as having the variables bar, bear and beer in your code, and 2) an indication that your names aren't descriptive enough, imo. The only valid reason I can think of for having the statement Foo foo; in the first place is if there's only ever going to be one Foo at a time (or you're passing that one Foo up and down function calls). This still isn't safe from future extensions of the code that might want to handle multiple Foos at a time, and is just, well, kind of unpleasant, I think. Call 'em FooType and foo and I'm happy.
Post a Comment
<< Home