I try to name a class (also members, properties and so forth) as exact as I can. But sometimes I’m not sure if this is so clever if the class name becomes huge (50 chars and more). The handling is so what uncomfortable and the code becomes difficult to read.
The question occured for me seldom and therefore I don’t have much experience with working with such long names but from time to time (now) it occurs. How other people handle this? Have you an approximate upper limit and then make abbreviations or is it worth the pain to handle such long names?
Update
As requested here an example of such a long class name.
ProjectContractChargingPeriodProjectAccountReferenceVM
The first Project represents the domain, it may be omitted because the namespace implies already that it handles projects. The problem with that is, that if I do this with this class name, then I must do it with all classes of this namespace and that I definitively don’t like because then many (short) class-names of this namespace will lose their expressiveness.
[Project]ContractChargingPeriod describes the object, this class is used for and ProjectAccountReference means that the class is a reference to a ProjectAccount
. With ProjectAccount is the same problem as with the ProjectContract. Only using Account is not meaningful because in the app exists also other Account-Classes. The Reference is a little bit weak because in reality it’s a little bit more than only a reference, but this is the general purpose. The VM is an abbreviation I always use and it stands for ViewModel. I think this is legal because everyone who works with WPF knows what VM means.
I have to say, that the class is used to wrap a class out of an ORM that is built with an elder tool I created a long time ago. The classes there represent quasi 1:1 the ERM and I am aware that this is not optimal, but changing it would be a major effort.