Our team does not allow single letter variables, not event in lamdas.
What we find is, just like in TSQL, the longer the code lives the more confusing it gets. As far as lambda's
We would do something like this:
people.Where(personFound => personFound.FirstName.Contains("blah!"));
That way the next dev will not have to look at
people.Where(p => p.FirstName.Contains("blah"));
It seems readable, but it always does at first
What about a join
citizenShip.Join(people, c => c.personid, p => p.persoinid, (p, c) => new { p.FirstName, c.IsCitizen})
.Where(pc => pc.FirstName.Contains("blah");
the same with variable names
citizenShip.Join(people,
citizenToJoin => citizenToJoin.personid,
personToJoin => personToJoin.persoinid,
(joinedPerson, joinedCitiznship) =>
new { joinedPerson.FirstName, joinedCitiznship.IsCitizen})
.Where(personAndCitizenshipFound=> personAndCitizenshipFound.FirstName.Contains("blah");
Oh but this is confusing and ugly. Just use differenct letters so it less confusing
citizenShip.Join(people,
c => c.personid,
p => p.persoinid,
(jp, pc) =>
new { jp.FirstName, jc.IsCitizen})
.Where(pc => pc.FirstName.Contains("blah");
Still confusing, but now its worse. So we break the lambda up so we refactor for readability
var peopleWithCitizenship = citizenShip.Join(people,
citizenToJoin => citizenToJoin.personid,
personToJoin => personToJoin.persoinid,
(joinedPerson, joinedCitiznship) => new { joinedPerson.FirstName, joinedCitiznship.IsCitizen});
var peopleWithCitizenshipFilteredByName = peopleWithCitizenship.Where(personAndCitizenshipFound=> personAndCitizenshipFound.FirstName.Contains("blah"));
This is not a perfect example but make the code readable with very little insider knowledge. We find this exposes complex code(lambda) which needs to be broke up into smaller chunks.