views:

267

answers:

7

The other day I was looking through our code and I came across a class name IdempotentObject I didn't know what this meant at the time so I questioned whether it was a poorly chosen name. I found out who wrote it and asked the developer why he had named it so confusingly. He was surprised that I didn't know what it meant and told me that it was a well chosen name because the object is Idempotent.

On one side I see an argument for keeping it simple and having everyone understand what everything is at first reading. On the other hand we have the idea that we should name things precisely and if you don't know the meaning look it up.

Which one is better, precise or easy to understand at a glance?

+8  A: 

Precise is more important. The initial developer or you could have left a comment afterward to explain the naming if it is not a term that can easily be found in a dictionary or generally known to the audience.

David Segonds
strongly disagree - the writer shouldn't be forced to second guess whether future readers will understand otherwise standard terms in CS, the OPs knee-jerk response is wrong
annakata
In this case a comment would be silly but I can see other cases where the initial developer uses some vocabulary that needs explanation.
Outlaw Programmer
This may sound silly but English being my second language, I had to look up 'idempotent'. I agree that in this particular case, depending on the audience (i.e. English speaking) the comment may not be warranted. In principle, the class should be commented to explain its purpose and responsibilities.
David Segonds
Plenty of free and easy to access online dictionaries. If a word has a well-known, well-defined meaning, either in a specific problem domain or in CS in general, it should be safe to use. As for comments... Put a glossary in the design document if you want, but leave comments for important stuff.
Shog9
Thank you for your feedback. I modified my answer accordingly. Or at least tried to. :-)
David Segonds
I don't think the comment should explain the meaning of the term... it should be known. but it's not a bad thing to describe your class, which if you do a good job will provide enough context for the reader to make a guess at the meaning of the term.
rmeador
@rmeador: i'll go along with that. Context is always good, as are comments explaining why code exists.
Shog9
any moderately complex design introduces specific terms, used in a specific way only for this design. of course, they must be documented. terms that you can find in literature can be assumed, or, if somewhat obscure or ambiguous, cite the definition you're using.
Javier
@David: I don't think it's an issue of an English-speaking audience. I can't think of any reason why I would expect my mother to know the term "idempotent". It's Computer Science/Abstract Algebra jargon, and should be known to anyone with that background; at least the concept, if not the word.
Adam Jaskiewicz
+4  A: 

I would recommend restricting names to one that are within the domain of the problem. Idempotent would be acceptable for a high level math application. I would prefer to use another name if this was an accounting application.

Comments can be helpful in some cases, but I prefer to change names.

Jim C
idempotent is a widely used term in CS. even accounting application programmers should know their literature
Javier
+14  A: 

No offence, but anybody with a CS degree or who hopes to practice in the field should recognize the term "Idempotent" as having a specific meaning in computer science even if you don't know the term and have to look it up.

On the other hand, I don't think objects should have the word "Object" in the name - that's redundant.

Now, if it were called "IdempotentDataAccessor" or something that is both precise and descriptive, that would be good.

Paul Tomblin
I think the "Object" part was just some anonymization. It was probably something like IdempotentMap or IdempotentBook. My biggest problem is that idempotence applies to functions, not objects.
Outlaw Programmer
No it was Object
Andrew Clark
Naming a class "Object" is ugly. You should be beating him for *that* part of the name!
Shog9
+1  A: 

Well, thats very subjective. Maybe for the guy who wrote the class the name was very easy to understand. Its very hard to determine what vocabulary is easy or hard to understand because the people who read the code can have many different backgrounds.

Megacan
+5  A: 

"I didn't know what this meant at the time so I decided that it was a poorly chosen name."

There's your problem. If you don't know what something means the correct response is to find out.

annakata
I did, I meant I didn't know when I read it.
Andrew Clark
I know, and the follow on "..so I decided" is where this is a problem. You can't make decisions when you aren't in possession of the facts.
annakata
That didn't come out right, your right about making uninformed decisions.
Andrew Clark
fair enough, didn't mean to take you to task unduly
annakata
+2  A: 

I can't think of any other concise way to describe idempotence. I don't think this is a problem, since idempotence is a very frequently used term in RESTful interfaces, and clear descriptions are easy to find in a Google search.

Adam Lassek
+3  A: 

As a developer you are used to seeing code, noticing a feature of a language or library which you aren't familiar with, looking it up, and incorporating it into your own usage of that language.

This is no different.

You don't of force others to avoid the lessor known features of C#, why would you do so for the English, or any other, language?

Look it up, learn it. Whether you use it is up to you, but please don't restrict other's usage. You have a reference.

Adam Davis