Friday 12 September 2008

Agent nouns are code smells

Class names ending in agent nouns are a code smell. An agent noun is:
any noun that denotes someone or something carrying out the verb's action, typically words ending in -er or -or
Classes with agent nouns are, the majority of the time, a sign of procedural thinking - especially agent nouns such as "manager", "helper" etc.   As the definition says it denotes the class is carrying out the verbs action.   This is contrary to good OOP where the verbs belong to the nouns themselves; classes which represent things are responsible for their own doings, not someone else. This reflects the real world where I am a Person able to do Programmer tasks, the verbs of programming are executed by me not some CodeProgrammer object which sits next to my desk.

Agent nouns are useful for describing roles which makes them good for interface names. A SpellChecker interface on a Dictionary class gives clear definition of the role (to check spelling) and allows the Dictionary to implement the verbs (check_spelling "word"), likewise a SynonymProvider sits well on a Thesaurus class.

So beware agent nouns; they are a language trick which fools you into believing that a class is a first class concept when really it's stealing someone's verb.

5 comments:

Anonymous said...

People should read this.

Anonymous said...

Well, I did read it. To understand it needs some background experience. That may be too much asked from (all) people but it made me happy as a rainbow

Keshet

Anonymous said...

I have been reading and looking for Agent nouns are code smells and is amazing and disturbing how many blogs related to viagra online are in the web. But anyways, thanks for sharing your inputs, they are really interesting.
Have a nice day

Anonymous said...

Although borrower is not at stake but bank is definitely vulnerable to losing their money. In the mean time, 2-year-old baby Sky's still lost and there haven't been any revisions in his event. In reality to be permitted you need a co-signer who will be to blame for you! instant payday loans Should you get a car or truck and need an auto loan after a a bankruptcy proceeding!

Anonymous said...

Factors that are considered during this process are current paycheck as well as virtually any assets you may have. Apr interest rates (annual percentage rate) sustain upon unsecured finance UK relies on filling an easy online application form with delivering there very few details. In all my well being, I can not keep in mind a single season when I would have ever referred to Christmas time to "stressful? sameday loans You'll want to mention the blueprint when you remedy the phone.

About Me

My photo
West Malling, Kent, United Kingdom
I am a ThoughtWorker and general Memeologist living in the UK. I have worked in IT since 2000 on many projects from public facing websites in media and e-commerce to rich-client banking applications and corporate intranets. I am passionate and committed to making IT a better world.