| WellBehavedCitizens |
UserPreferences |
| JicarillaWiki | FrontPage | Overview | Articles | GetStarted | Sourceforge Project Page | RecentChanges |
This wiki is in 'slumber' mode, just like its associated sourceforge project. Edits are disabled, the content is potentially stale and is not maintained. That said, it contains some really useful stuff still. Enjoy!
"Well-Behaved" is a term often accredited to Joshua Bloch when spoken about with regard to java. It can apply to classes, objects, whole jar files, programs, groups of programs, whatever. A well-behaved citizen is a citizen that follows all the rules and contracts that exist in its environment, and in addition to those, also follows most if not all guidelines, best practices, common idioms, coding standards, etc.
While its a though task to make all our classes and programs be well-behaved, especially if they are ment to be used in different environments, we should always strive to do so.
In no particular order, a highly incomplete list:
Always follow the code conventions of the surrounding context. When adding a method to an existing class, apply the same code conventions that govern the rest of the class. When adding a new class to an existing package, apply the code conventions of that package. Be consistent in following those conventions.
There is almost never a valid case for the creation of new threads within a constructor. Threads should be created after an object is constructed. Thread creation, destruction and management is often error-prone code and often the cause for much confusion. Hence, we should attempt to isolate it from the rest of the code (create threads in an initialize() method, destroy them in a dispose() method, use an execution framework).
Make good use of the existing mechanisms in java for managing concurrency: synchronization and ThreadLocals. When they do not suffice, use the util.concurrent package from Doug Lea; don't roll your own!
All objects that are referenced from anywhere should always be in a safe state, that is, it should be legal to call their public methods (see JavaBeans Considered Evil for more about safe state).