This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clean Code A Handbook of Agile Software Craftsmanship - Meaningful Names

 
Tomasz Prus
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about such class names like "ThreadSafetyAdministratorHibernateDAO", is it good? Sometimes there is really problem
 
J. Nuno
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I wonder if all classes on each layer (dao, ejb, entity, view, controller) should have common name endings like Tomasz suggested "ThreadSafetyAdministratorHibernateDAO" or be placed in a meaningfull package and drop the ending like com.myapp.server.dao.ThreadSafetyAdministratorHibernate?

Thank you!
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frankly, I'm undecided on the length of the name. But besides that, I'd think that the name might better be

ThreadSafeHibernateAdministratorDAO
 
Travis Scheponik
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my honest opinion it really comes down to preference. As long as you are not writing a paragraph for a name you should be fine, I have seen some horrible names in my short time in this field example being doThreadFailAB123
not one person in the whole place knew what it did nor were there any other methods that would indicate a <122 it was just a sad, sad day for me.
 
Paul Croarkin
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be careful with a name like that unless you can back it up (with tests) to prove that it is ThreadSafe.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Croarkin:
Be careful with a name like that unless you can back it up (with tests) to prove that it is ThreadSafe.


I agree that you should "prove" it. (Although I hope that you are aware that tests don't actually *prove* a lot.) But even if you don't, the name would at least communicate intent. When maintaining code, knowing what the code was supposed to do often is even more important than knowing what it actually does. (The latter can always be tried out, the former might be lost forever otherwise.)
 
Robert Martin
Author
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tomasz Prus:
What about such class names like "ThreadSafetyAdministratorHibernateDAO", is it good? Sometimes there is really problem


I guess it depends on whether that class is the Hibernate implementation of the DAO that has the CRUD functions for ThreadSafetyAdministrator instances.

If not, then I think that name could probably use a bit of work.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Robert Martin:


I guess it depends on whether that class is the Hibernate implementation of the DAO that has the CRUD functions for ThreadSafetyAdministrator instances.

If not, then I think that name could probably use a bit of work.


What name would you you give to a thread-safe hibernate implementation of a DAO for Administrator instances?
 
Robert Martin
Author
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:


What name would you you give to a thread-safe hibernate implementation of a DAO for Administrator instances?


;-) Since all classes should be thread safe, I would simply call it AdministratorDAO. I would put the ThreadUnsafe prefix on it if it wasn't thread safe....
 
arulk pillai
Author
Ranch Hand
Posts: 3380
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as a consistent approach is used for naming I am happy.
 
Vijay Venkat
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

;-) Since all classes should be thread safe, I would simply call it AdministratorDAO. I would put the ThreadUnsafe prefix on it if it wasn't thread safe....


That's very interesting. This make me think harder.

1. Yes we do strive to make class immutable.(Implies it is thread safe)
unless on is exposing the internal implementation to be manipulated outside it.

2. While that is the case, there are place where we use lot of bean classes which have setters and getters, in these places, we don't make them thread safe, but expect a instance of this created and for each operation, and leave it to the client class handle the threading if it is really required.

3. Let us take instance of java's HashMap, we don't need thread safe instance always. If we have all of objects thread safe, will it not lead to performance problem?
We use thread safe version of HashMap only when it is needed.
Isn't that we need to think of the usage, while we decide to make any class thread safe or not?

4. Another note on the class name - If the class name is not clear, all i can conclude is, the coder/developer is not clear of what he is doing or has a very poor coding discipline.
 
Tomasz Prus
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heh Nice discussion but i wrote this class name only for example as a very long name. Probably i could use name "BlebleAbrakadabraSomethingClassName"
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Long class names are not a bad practice at all. You just need to make the class name descriptive of what it does, and not make it longer than it should be. If you can name a class clearly using 10 characters, don't use 20. If you need a 100 characters to make it clear, so be it. Don't give it a name of 15 characters because you don't want a long name
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic