The problems with Avoiding Smurf Naming classes with namespaces
Posted
by
Daniel Koverman
on Programmers
See other posts from Programmers
or by Daniel Koverman
Published on 2013-03-25T22:53:10Z
Indexed on
2014/08/20
4:30 UTC
Read the original article
Hit count: 452
naming
|coding-standards
I pulled the term smurf naming from here (number 21). To save anyone not familiar the trouble, Smurf naming is the act of prefixing a bunch of related classes, variables, etc with a common prefix so you end up with "a SmurfAccountView passes a SmurfAccountDTO to the SmurfAccountController", etc.
The solution I've generally heard to this is to make a smurf namespace and drop the smurf prefixes. This has generally served me well, but I'm running into two problems.
I'm working with a library with a
Configurationclass. It could have been calledWartmongerConfigurationbut it's in the Wartmonger namespace, so it's just calledConfiguration. I likewise have aConfigurationclass which could be calledSmurfConfiguration, but it is in the Smurf namespace so that would be redundant. There are places in my code whereSmurf.Configurationappears alongsideWartmonger.Configurationand typing out fully qualified names is clunky and makes the code less readable. It would be nicer to deal with aSmurfConfigurationand (if it was my code and not a library)WartmongerConfiguration.I have a class called
Servicein my Smurf namespace which could have been calledSmurfService.Serviceis a facade on top of a complex Smurf library which runs Smurf jobs.SmurfServiceseems like a better name becauseServicewithout the Smurf prefix is so incredibly generic. I can accept thatSmurfServicewas already a generic, useless name and taking away smurf merely made this more apparent. But it could have been namedRunner,Launcher, etc and it would still "feel better" to me asSmurfLauncherbecause I don't know what aLauncherdoes, but I know what aSmurfLauncherdoes. You could argue that what aSmurf.Launcherdoes should be just as apparent as aSmurf.SmurfLauncher, but I could see `Smurf.Launcher being some kind of class related to setup rather than a class that launches smurfs.
If there is an open and shut way to deal with either of these that would be great. If not, what are some common practices to mitigate their annoyance?
© Programmers or respective owner