Irwell
Well-Known Member
Again, though, my preference would be to work in the same way even with a smaller project, mainly for some kind of continuity.Damocles said:To be honest now you've described the project's size, it's a little clearer why you would have functions with loops moving into the several hundred line mark.
If someone is sticking together a short script for a one-off task to maybe assure the data integrity of a part of the database or to correct something that has gone wrong then I would have no issue with it. The developer would be working alone on the code, though obviously the design authority and testers would be involved, and there would be little chance of any situation where the code was reused by another developer. If, however, it was in part of the system itself then it would have to be changed, not through some OCD behaviour on my part but because that is what both our employer and the client want. If we worked somewhere with a naming convention that allowed for the use of i then obviously there would be no problem.Damocles said:True, and those are the cases whereby index variable naming is a logical thing to do. I think we're arguing from different scopes here and trying to apply a universal rule. You're arguing from the several million line project ideal where I'm arguing from the run of the mill project ideal. Like anything else, you adjust to suit. I'm sure that if you had a single loop somewhere, maybe iterating through a connection array or something trivial, you wouldn't tick up a fuss for int i?
Not particularly, just that anywhere the functionality isn't clear from the code, for example you perform four functions in a set order but there is no indication why they are performed in that way, then there should be a comment explaining it. If the functionality is clear then there is no need. Obviously, though, we do have predefined header comments that go along with each class and function.Damocles said:The JavaDoc/Doxygen style is something that I do find attractive and has lots of uses for. Like anything though, it has to actually be used well otherwise it detracts rather than adds to understanding. Do you guys legislate on commenting at all?
Again, our naming convention is kind of a hybrid. For functions we would use a more descriptive form, but in camelBack notation, i.e. countOnlineUsers(), but we would include the scope of the function in the name too, i.e. mcountOnlineUsers().Damocles said:I tend to "think" in Linux naming conventions originating from C as that's what I learnt with. So for me, I would use things like count_online_users() rather than iCntOnUsers()
To quote Linus here on the kernel naming conventions:
C is a Spartan language, and so should your naming be. Unlike Modula-2
and Pascal programmers, C programmers do not use cute names like
ThisVariableIsATemporaryCounter. A C programmer would call that
variable "tmp", which is much easier to write, and not the least more
difficult to understand.
LOCAL variable names should be short, and to the point. If you have
some random integer loop counter, it should probably be called "i".
Calling it "loop_counter" is non-productive, if there is no chance of it
being mis-understood. Similarly, "tmp" can be just about any type of
variable that is used to hold a temporary value.
I would agree with Linus, calling a loop counter "loop_counter" rather than i would be meaningless. Every man and his dog who has looked at some code knows that i is a loop counter, so it would just be a waste of time. Also, from a kernel perspective they would want to reduce memory use as much as possible and so not be defining variables unnecessarily. User space applications have much fewer such restrictions as the memory usage is much less important these days and it was never my argument that the descriptive name for the variable should just be something like "loop_counter". That simply describes what the purpose of the variable is, not what the meaning of the data within it is.
I still prefer to think of myself as a developer!Damocles said:I think our thoughts are different because you're a project manager and I'm a developer. I expect other developers to understand my code simply because anybody who has coded for more than a few minutes (and some that haven't) can probably work out what "tmp" mean in the context of the overall. You don't have the luxury of presumption and when that new hire who didn't quite tell the truth about his experience bombs an entire module because of it, it's you who gets shouted at and not me.