Views
#77: Inconsistency with pointers and references
View
(Anonymous)
issuedata
Classification:
Bug
Topic:
Backend
Importance:
Medium
Assigned to:
Created by: drussel
Created at: 2007-10-16
progress
Deadline:
2007-10-30 02:45 AM
Hours estimated:
0
Hours needed:
0
Percent done:
0
contact
Name:
Daniel Russel
E-Mail:
drussel@salilab.org
Description:
The library interface implies that the Element object is copied internally into the Atom like the string fields since the set method takes a const reference and the get method returns a const ref. However, acting on this implication is pretty catastrophic :-( Suggestions: - make Atom::getElement() and PTE::getElement() return pointers - make Element noncopyable since the instances are just supposed to sit in their table As a general point, having objects take other objects by reference and then storing a pointer to the passed object violates most C++ conventions and invites all sorts of problems if, as in this case, the user gets confused. If the attribute is a pointer to an external object, setting it should take a pointer. If the attribute is an object the set function should take an object. The fact that the field is documented as a pointer doesn't really solve the problem since one doesn't know if that is simply to avoid the memory allocation if the Element is not set.
Transcript
#1:
2007-10-16 03:57 AM (drussel)
topic: "" ->
"Backend"
title: "" ->
"Inconsistency with pointers and references"
description: "" ->
"The library interface implies that the Element object is copied internally into the Atom like the string fields since the set method takes a const reference and the get method returns a const ref. However, acting on this implication is pretty catastrophic :-(
Suggestions:
- make Atom::getElement() and PTE::getElement() return pointers
- make Element noncopyable since the instances are just supposed to sit in their table
As a general point, having objects take other objects by reference and then storing a pointer to the passed object violates most C++ conventions and invites all sorts of problems if, as in this case, the user gets confused. If the attribute is a pointer to an external object, setting it should take a pointer. If the attribute is an object the set function should take an object.
The fact that the field is documented as a pointer doesn't really solve the problem since one doesn't know if that is simply to avoid the memory allocation if the Element is not set. "
PloneCollectorNG (C) 2003-2004 by ZOPYX - Software Development and Consulting Andreas Jung