No, the doing-it-all-on-one-line bit. What does this do?
int* x, y, &z;
Is this easier to read?
1 2 3
int *x
, y
, &z;
If you dislike both styles, the preferred method is one-by-one:
1 2 3
int *x;
int y;
int &z;
Though when I see individual declarations instead of comma-separated declarations, it changes the connotation of the code from "these are related" to "these are unrelated".
but the way you did int* x and than later did int *x :D
Trying to make it harder
The first way is more clear to me as the second its kinda saying that this is a statement on its own.
With arrays they have braces {} so you can work it out
@LB
I have never understood why so many say it isn't readable. Your first line is perfectly readable to me. x is a pointer to int, y is an int, z is a reference (granted it will return an error for being uninitialized). That has always confused me, some of the examples people give for being unreadable, to me, usually isn't all that hard to read.
When you are only look at it as a single line in a forum post it is still quite readable yes, but when you have been scanning and reading thousands of lines of code to find a bug or just to find out what something does for the last few hours it can easily be missed.
@Fredbill
What do you mean? That vector iterator code is perfectly readable - it took me a while to work out what you find hard about it (I assume its the brace placement?).
It's probably because the identifiers are all underscores followed by a capital letter - the standard reserves those for the implementation to use so as not to interfere with user code.
I have always advocated "Indent with tabs, align with spaces" as MiiNiPaa suggests, since the tabs can always be converted to spaces by picky programmers. The reverse conversion is more difficult, however, as a simple find and replace will grab the secondary indentation incorrectly.
Yeah I can see why some would consider that hard on the eyes.
@NT3
Yeah it is readable, but I'm like you that isn't hard on my eyes.
Everyone has different coding styles, but I don't find it hard on my eyes personally. As for tab/spacing, I have to agree as my first IDE was Rhide (sometimes wish it was still maintained so I could still use it for nostalgia reasons) that didn't do anything for you except highlighting the keywords.
Personally I don't think anyone on here could explain there whole style because its just so many rules to adapt to. This is my style:
1 2 3 4 5 6 7 8 9 10 11 12
// Variables
int number = 1;
string playerName = "Bob";
// Main method
int main()
{
if (number = 1)
{
cout << "With the number " + number + " " + playerName + " won the ticket to Adventure Island." << endl;
}
}
Lol? This <> source code format is going out of the text box.