Monday, January 15, 2007

Ineffective C++

I'm currently porting my protein simulation program from Java to C++. At the same time I have started reading the classic book by Scott Meyers "Effective C++" (which, incredibly, does not have a wikipedia-page).

Item 19 in the book is a list of things to consider when designing a new class. It strikes me that the considerations are a strict superset of the things to consider when designing a new class in Java.
  1. How should objects of your new type be created and destroyed?
  2. How should object initialization differ from object assignment?
  3. What does it mean for objects of your new type to be passed by value?
  4. What are the restrictions on legal values for your new type?
  5. Does your new type fit into an inheritance graph?
  6. What kind of type conversions are allowed for your new type?
  7. What operators and functions make sense for the new type?
  8. What standard functions should be disallowed?
  9. Who should have access to the members of you new type?
  10. What is the undeclared interface of the new type?
  11. How general is your new type?
The corresponding book for Java "Effective Java" doesn't have a similar item, but I'd say that 1,2,3,6 clearly don't apply to Java. 8 only applies in a very limited sense. Almost half the points to worry about, to create a class in Java, compared to C++. Hmmm....