The importance of formatting formatting
How important to readability is the code in this form:
public void DoStuff()
{
var v = new Object();
v.PropertyID = "abc";
v.Type = "abc";
v.Style = "abc";
v.SetMode(Mode.Abc);
v.Draw();
}
against.
public void DoStuff()
{
var v = new Object();
v.PropertyID = "abc";
v.Type = "abc";
v.Style = "abc";
v.SetMode(Mode.Abc);
v.Draw();
}
I love how the first style is best, it reads easily, how would you gently guide people towards the first and away from the last? Or don't you want to?
a source to share
Do people actually write code similar to the latter? This is a maintainability nightmare.
I would argue that it doesn't really matter what your conventions for code formatting are - more than that you follow them consistently. The first example is incompatible and therefore unreadable and unattainable.
If you have problems guiding people towards consistency, ask them to go back to maintain very controversial code after a year.
a source to share
If this was my code, I would do it like this:
public void DoStuff()
{
var v = new Object();
v.PropertyID = "abc";
v.Type = "abc";
v.Style = "abc";
v.SetMode(Mode.Abc);
v.Draw();
}
Thus, it determines which strings are property assignments and which are method calls.
I also agree with Jamie's answer, which says that "the format is very important, although not essential." The important thing is that the formatting isn't so bad that it hinders the ability of others to read it. I don't believe a few extra tabs or new lines will make a huge difference to a competent programmer most of the time.
a source to share
If you want to be kind, give them the Complete code to read. If you want to be average, introduce subscript errors like this in your code:
if (x==y);
DoSomething(); else
DoSomethingElse();
while(Whatever)
SomeFunction();
(If they find the error in less than one day, you're not high enough.)
a source to share
I prefer your spacing, although I would do it a little differently. I believe your most important question is how to convince someone that your approach is best: formatting your code can be very subjective. Some people object because it takes too long to get right. Others object because the team has no coding standards. Some objects because it feels like it is full of the neck.
The best way is to work with your team to build consensus that your particular approach is best practice. This is true if you are a leader or if you are an individual contributor.
Once the general consensus within the team is generally accepted (it may not be universal), I find that code reviews are the best place to enforce team practice. I suggest that you find peer pressure - this is the most effective way to encourage others to follow accepted best practices. Corruption is often true; it is difficult for one person to do such a thing in a team without consensus.
Here are some of my related StackOverflow answers
a source to share
As others have said, the first example is the norm; the second is different from him.
Also, make sure everyone working with the same set of files has the same convention for what a "tab" is. Your best bet is to define this as the number of spaces and make sure all text editors and IDEs agree.
It's a shame when three or four people work in the same SVN repository and edit each file with different distance conventions.
a source to share
The second method doesn't look very good. Avoid this.
I also think people tend to get addicted to formatting. In a month, another guy will come and want this format
public void DoStuff()
{
var v = new Object();
v.PropertyID = "abc";
v.Type = "abc";
v.Style = "abc";
v.SetMode (Mode.Abc);
v.Draw ();
}
It gets pretty silly and quite difficult to work with.
If people code this way, specify your arguments and programming capabilities.
a source to share