I'm talking about the literal use of the word 'foo' as a placeholder in a code example. I believe when giving someone example code it is always better to use a concrete example, even if the names are irrelevant to the question.
Many people seem to disagree with this and claim that using a concrete example is distracting because you are adding extra domain information. I don't agree and find that having something concrete in your mind makes it much easier to understand a concept that using pure abstraction.
In my opinion it is easy for a reader to take something specific and generalize it than to just have the general description straight up. My question is should this practice be avoided if possible?
Edit: Here is a code sample:
public class Foo
{
}
public class Bar
{
}
public class DerivedA<GenericDerived> : BaseA<GenericA1, GenericA2>
{
}
public class DerivedB : DerivedA<Foo>
{
}
public class DerivedC : DerivedA<Bar>
{
}
public class DerivedD : List<DerivedA<Foo>>
{
}
public class MainClass
{
public void Build()
{
DerivedD derivedD = new DerivedD();
derivedD.Add(new DerivedB());
derivedD.Add(new DerivedC());
// ...
}
}
Now tell me why I'm getting an error on the last line. Here is the same code with less general naming:
public class Bamboo
{
}
public class PalmTree
{
}
public class PlantHeight<T> : Dictionary<DateTime, double>
{
}
public class BambooHeight : PlantHeight<Bamboo>
{
}
public class PalmTreeHeight : PlantHeight<PalmTree>
{
}
public class GardenHeight : List<PlantHeight<Bamboo>>
{
}
public class MainClass
{
public void BuildGarden()
{
GardenHeight gardenHeight = new GardenHeight();
gardenHeight.Add(new BambooHeight());
gardenHeight.Add(new PalmTreeHeight());
// ...
}
}
I claim the second one is much easier to comprehend due to the specific domain information included.
foo
orbar
is ok.public class GardenHeight : List<PlantHeight<Bamboo>>
is wrong, because a garden contains all types of plants, not just bamboo.