I would like to spark a debate similar to that of Grant Skinner’s post about curly braces. Perhaps not such a large debate as I’m sure a lot less people view my blog and it’s probably not such a hotly debated topic (I have had endless conversations about whether to wrap my braces or not – I’m a wrapper myself).
This debate is about naming conventions, and in particular using an underscore in your variable names. The reason for this debate is this – I use underscore for private variables that have getters or setters, I think it keeps them all closely linked and would be easy for someone else to understand when picking up my code. So for example my code would look something like this:
Now I thought that’s what most people do but having spoke to a few people lately it seems some people just don’t like using underscore. The main reason seems to be that visually people don’t like it – a poor reason if you ask me but programming can be like art, and if you are staring at code all day I guess it makes sense for it to look nice!?
So what are your thoughts and what do you do? I’m interested to know what naming conventions people use. I code in FDT and it uses underscores when you automatically create getters and setters, so do most people go with the same naming convention as me? Or do you use it the other way wrong so your getters/setters have the underscore rather than the variable name?
One thing I will say is that what ever you do, whether you use underscores or some other naming conventions that you’ll hopefully share with us, you should always keep it consistent throughout your code.