vendredi 27 février 2015

Indenting Visual Studio if tests for readability with auto-formating on paste on

I have a habit of indenting my if tests to make them more readable. I have not seen anyone else do it in quite this way. In general I like the Auto-format on paste option on. Unfortunately if cut and paste:



if ( ( (!CurrentObject.IsInitialized)
&& CurrentAction == Action.Initializing
)
|| ( (!CurrentObject.IsInstalled)
&& CurrentAction == Action.Installing
)
)
{
// Do something.
}


It becomes:



if (((!CurrentObject.IsInitialized)
&& CurrentAction == Action.Initializing
)
||((!CurrentObject.IsInstalled)
&& CurrentAction == Action.Installing
)
)
{
// Do something.
}


Then I need to re-edit it to put the spacing back in. What is odd is that the indenting is not even consistent.


If tests indented in this style allow you to have more complicated if tests that are still readable and understandable. Allowing you to easily see what clause is being ored or anded with which.


I would advocate indented if tests as being more readable and get them added as an optional auto-formating option. For the time being I think I will have to live with auto-formating on paste off.


If people like the idea how does one propose this sort of change to microsoft? I would like to know how many people having seen this think it is a good idea.


For people who think it takes too many lines there is shorter variant that puts all closing brackets on the last line of a clause.



if ( ( (!CurrentObject.IsInitialized)
&& CurrentAction == Action.Initializing)
|| ( (!CurrentObject.IsInstalled)
&& CurrentAction == Action.Installing))
{
// Do something.
}

Aucun commentaire:

Enregistrer un commentaire