Take the 2-minute tour ×

I do a lot of flat-file processing to extract data. The file "formats" are very unique and each file format requires a lot of format-specific code. Sometimes, the parsing code needs to maintain a lot of state while the file is being read. I've used something like this "pattern" at times:

parser = New FileTypeAParser(filename)
data = parser.ParsedData

Or, consider a class that factors large numbers. For efficiency reason, upon being instantiated, the class would internally generate and cache list a primes. It would then be called many times with different numbers like this:

factors = factorizer.Factor(veryLargeNumber)

Original Question

The adage is Class names should be nouns; method names should be verbs. Is it a code smell to name and use classes in the way shown in the examples? If so, how do I refactor the examples to deodorize them and remove the code smell?

Revised Question

Based on the comments, I now realize that I am using nouns. After putting more thought into it, I realized that my concern is that these classes very verb-like in substance and in name. Is this something to be concerned about?

share|improve this question

closed as unclear what you're asking by Robert Harvey, gnat, Bart van Ingen Schenau, ChrisF Dec 10 '13 at 9:13


What are you talking about? All of your class names are already nouns, not verbs. –  Robert Harvey Dec 10 '13 at 3:40
I thought Parser and Factorizer (Factorer?) were nouns. –  Steve Evers Dec 10 '13 at 3:41
@RobertHarvey I see Execution in the Kingdom of Nouns as the extreme version of what this question is about. –  Izkata Dec 10 '13 at 3:57
Even if you had verbs as object names, there's an overriding principle that might justify it. The name should match the abstraction provided. For example, a C++ object who's main purpose is to act like a function (the class overrides the operator() method) might be named with a verb. I can't imagine a case where the class should be named as a verb, but if it's possible, the same overriding principle should apply - the name should match the abstraction. –  Steve314 Dec 10 '13 at 4:16
@Scottie: No, in the sentence "the cutting was done quickly" "was done" is a verb and "the cutting" is a subject. The form "cutting" is also used as part of verb in progressive tense ("he is cutting"), but in this context it acts as noun. –  Jan Hudec Dec 10 '13 at 7:33

1 Answer 1

up vote 1 down vote accepted

It's not "verb like", it's a state. If you have a process with sufficiently complex state, where else would you put it if not in a class.

What might be a code smell is a class with methods that have to be called in particular order. A single parse method that will return the parsed data, it is easier to use than leaving the data in the object to be picked up by separate call. Of course provided the whole operation can be done in a single step no matter how complex.

Alternatively you could have the data class with a parseFrom(File) method (which would internally create appropriate parser class (which would be internal or even inner).

share|improve this answer
