Some of the legacy code I've inherited uses the fact that C# supports multiple assignment to write code like:
void DisableControls()
{
ddlStore.Enabled =
ddlProgram.Enabled =
ddlCat.Enabled =
btnSaveProxy.Enabled =
btnCancelProxy.Enabled =
btnViewMassManagerProxy.Enabled =
grdPromo.Enabled = false;
}
It's a very pretty style, with all the =
lined up neatly, and the value being assigned down at the bottom, but it's also a rather annoying one to work with. (And yes, those are tabs lining things up, not spaces).
I would like to know what, if anything, this style implies about the original coder, since I've only seen it on a few occasions before. Does it indicate a C++ background? .NET 1.1? Just someone's personal preference?
Is there any reason that the chained assignment like this would be more efficient than individually setting each control's (This part was answered by @gnat's comment: .Enabled
? Less so?This way makes it easy to insert btnWhatever.Enabled = as new buttons are added and delete as some buttons are deleted
)
Edit: Other elements of this person's style, assuming the whole file was written by one person (likely but not certain), include putting function arguments on the next line, and putting commas at the beginning of a line instead of the end of the previous line. Example:
PromoUpdate[] GetPromoUpdates(
StateField field)
{
List<PromoUpdate> updates = new List<PromoUpdate>();
foreach (PromoOptInState p in field.States.Where(
x => x.IsDirty))
{
updates.Add(new PromoUpdate() {
promoCode = p.Code
, optIn = p.IsOptedIn
});
}
return updates.ToArray();
}
It's very weird.
btnWhatever.Enabled =
as new buttons are added and delete as some buttons are deleted. Sort of cargo cult - makes it easier to copy-paste stuff instead of having a list and iterating over it