Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

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
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.