Naming is matter
Consider code block, can you spot an error in a second given its full with additional business logic details?
/* somewhere far away (written in small letters)
ValidatedBrewIntervals.Add(RecipeBook.Default.BeanTypeId);
*/
class CoffeeRecipe
{
int BeanTypeId { get; set; }
int BrewIntervalId { get; set; }
}
ISet<int> ValidatedBrewIntervals = new HashSet<int>();
void ValidateReceipes(IEnumerable recipes) {
foreach(var recipe in recipes) {
if(!ValidatedBrewIntervals.Contains(recipe.BrewIntervalId)) {
ValidatedBrewIntervals.Add(recipe.BrewIntervalId);
}
}
}
I couldn't and spend too much time figuring out trivial bug. What if I would get this block to work with instead.
ISet<int> ValidatedBeanTypes = new HashSet<int>();
void ValidateReceipes(IEnumerable recipes)
{
foreach(var recipe in recipes)
{
if(!ValidatedBeanTypes.Contains(recipe.BrewIntervalId))
{
ValidatedBeanTypes.Add(recipe.BrewIntervalId);
}
}
}
Much easier to spot.
Naming is matter.
Name things as best (closest to reality) as you can as soon as you can.
1/30/2023