I like the field prefix with underline, as others have mentioned.
private int _x;
I think this goes beyond direct personal preference (as David Arnault said in this thread). I think there are some real objective reasons for this:
- This means that you do not need to write "this.x = x" for assignments (especially in setters and constructors).
- It distinguishes your fields from your local variables / arguments. This is important to do: fields are more difficult to process than local ones, because their scale is wider / longer. Adding an extra character is a bit of a warning sign for coders.
- In some IDEs, underlining will force autocomplete to sort the fields at the top of the offer list. This makes it easy to see all the fields for a class in a single block. This, in turn, may be useful; on large classes, you will not be able to see the fields (usually defined at the top of the class) on the same screen as the code you are working on. Sorting them to the beginning gives a convenient link.
(These conventions are for Java, but similar ones exist for other languages)
These things seem small, but their prevalence definitely makes my life easier when I code.
source share