I code quite differently to your average developer, and as (kind of) requested, im going to explain why my method of coding is superior to any one elses.
Many developer place their braces on the same line as the control block statement as such:
if (var == true){ //code }
I personally put braces on new lines
if (var == true) { //code }
The main argument for the former style is that "it takes up less space so you can view more code on the screen". In the 21st century where 2k monitors exist, saving a line of code here or there really isnt a valid argument. Especially when source files can most of the time fit all on one screen. Code folding also exists in many good IDEs.
The reasons why I use the latter style is because
What annoys me even more is when people do this:
if (var == true){ //code }
If you're going to leave a space after the control statement anyway, you may as well put the brace there.
In my code, I never use single letter variable names (excluding x, y, and z for co-ordinates).
When doing things such as
for (int i = 0; i < 100; i++) { //code }
The variable i, even if it's local to only that block, is a very bad practice as it does not clearly describe
In a for statement, you can have multiple counters
for (int i = 0, j = 10; i < 100; i++, j--) { //code }
This can quickly become messy and unreadable.
for (int arrayIndex = 0, speed = 10; arrayIndex < 100; arrayIndex++, speed--) { //code }
Is much better and more readable.
I always use tab indentation. There is absolutely no reason not to use tab indentation. If you prefer 2 spaces to a tab, then get a decent IDE and set the tab width to 2 spaces. There is no excuse for this poor practice.
This is just my personal preference, but I prefer to camel case my variable names as such: int testVariable = 0; and capitalise my class names as such: TestClass.c
There should be a space after and before all punctuation (except semicolons and fullstops). You code should be grammatically correct and should practically be a readable sentence.
for (int index = 0; index < 100; index++)
Not
for (int index=0; index<100; index++)
I also prefer to space after the control name, but not method names. It separates the control block name and makes it look less cluttered.
The only time I comment, is when creating Javadoc for my methods. The code should be as simple and concise as possible. If your code needs comments to explain what its doing, you're doing it wrong. Documentation on what the method does is fine though, a developer should be able to know exactly what a method is doing through either the method documentation, or the method name.
I personally prefer to put annotations on the same line as the code its annotation, to me it looks and reads nicer, plus when you have multiple annotations for a single line of code, it ends up pretty messy.
@Getter @Setter @InjectView(R.id.test) private View test; @Getter @Setter @InjectView(R.id.test2) private View otherTest;
instead of
@Getter @Setter @InjectView(R.id.test) private View test; @Getter @Setter @InjectView(R.id.test2) private View otherTest;
For the love of god, if you're going to code, at least be consistent with the way you do. If you work on a project with another developer, follow by their coding style. Seriously, the amount of time both of you will save is phenomenal.
Edit: spelling.