Naming issue

  • Follow


I have a class that holds a sequence of data items. Modifying those 
items is the sole domain of the class itself. However, the user has 
read access to the data, e.g. to gather statistics. This access is 
via an iterator range. While there is one unrelated place I might add 
a write hook later, I'm positive that write access through the range 
interface will never make sense. Given that, can I call the iterator 
type just "iterator" for convenience or should it be "const_iterator" 
for conceptual accuracy? What do you think?


Martin

-- 
Quidquid latine scriptum sit, altum viditur.
0
Reply martin.eisenberg (676) 12/16/2005 2:05:36 AM

After I asked (and got good answers, thanks to Victor Bazarov) a few
similar questions to yours now I'd say something like this:

"Ask yourself if such name would be clear for you and if you'd be able
infer from such name it's character - the constness - easily or not?"

Cheers
--
Mateusz Loskot
http://mateusz.loskot.net

0
Reply mateusz1 (61) 12/16/2005 3:29:16 AM


Mateusz Loskot wrote:

> After I asked (and got good answers, thanks to Victor Bazarov) a
> few similar questions to yours now I'd say something like this:
> 
> "Ask yourself if such name would be clear for you and if you'd
> be able infer from such name it's character - the constness -
> easily or not?" 

In view of your posts in that thread, I'm not sure if the above is 
supposed to be a real or a rhetoric question. I do believe the answer 
to the first part would be Yes for *me* once I'd grasped what the 
class does, but that's a hazardous way to write code for others to 
use. Regarding the second part, I want to know what the cognitive 
burden on *other* people is when the overall semantics of an 
interface takes precedence over conventional connotations of a member 
name.


Martin

-- 
Quidquid latine scriptum sit, altum viditur.
0
Reply martin.eisenberg (676) 12/16/2005 4:01:14 PM

I think, after your second post, I get your point better.
It seems that "overall semantics interface of your class" is more
importand than semantics of individual members of that interface. I
also think right answer will be much subjective.

As such, I still think semantics of individual members of interface is
very important and should be as clear as possible, or even predictable.
So, "conceptual accuracy" is also very important at the level of
individual member functions.

Consequently, if semantic of access is const in manner of whole object
- provides read-only access to data managed by object - I'd use
const_iterator + member function declared as const.

Cheers
 --
Mateusz Loskot
http://mateusz.loskot.net

0
Reply mateusz1 (61) 12/16/2005 11:40:58 PM

Mateusz Loskot wrote:

> It seems that "overall semantics interface of your class" is
> more importand than semantics of individual members of that
> interface. I also think right answer will be much subjective.
> 
> As such, I still think semantics of individual members of
> interface is very important and should be as clear as possible,
> or even predictable.

I guess you're right. Since this was the last decision to make before 
relabeling the thing from beta to 1.0 and no others have given their 
opinion, I've decided to assume that they're silently shaking their 
heads and go for const_iterator. If you want to see what this was 
about anyway, look here: http://www.aphoria.de/code/diffevol-1.0.zip


Martin

-- 
Quidquid latine scriptum sit, altum viditur.
0
Reply martin.eisenberg (676) 12/17/2005 12:28:30 AM

Martin Eisenberg wrote:

> I have a class that holds a sequence of data items. Modifying those 
> items is the sole domain of the class itself. However, the user has 
> read access to the data, e.g. to gather statistics. This access is 
> via an iterator range. While there is one unrelated place I might add 
> a write hook later, I'm positive that write access through the range 
> interface will never make sense. Given that, can I call the iterator 
> type just "iterator" for convenience or should it be "const_iterator" 
> for conceptual accuracy? What do you think?


You should have both, and typedef them to the same type.
Then you should document the behaviour of course.
I'd guess there's not a strong expectation that Type::iterator
must be mutable (think set::iterator, or a container passed by
const reference to some function), but users would expect
both declarations to compile:
   YourClass::const_iterator it = a.begin();
   YourClass::iterator it2 = b.begin();


	homsan

0
Reply nowhere8882 (18) 12/17/2005 12:34:21 AM

Martin Eisenberg wrote:
>
> If you want to see what this was
> about anyway, look here: http://www.aphoria.de/code/diffevol-1.0.zip
>

Unfortunately, I can not say much about it because I'm not an expert of
genetic algorithms but sounds intersting :-)

Cheers
--
Mateusz Loskot
http://mateusz.loskot.net

0
Reply mateusz1 (61) 12/17/2005 1:38:48 AM

homsan toft wrote:

> Martin Eisenberg wrote:
> 
>> Given that, can I call the iterator type just "iterator" for
>> convenience or should it be "const_iterator" for conceptual
>> accuracy? What do you think?
> 
> You should have both, and typedef them to the same type.

That's interesting, thanks!


Martin

-- 
Quidquid latine scriptum sit, altum viditur.
0
Reply martin.eisenberg (676) 12/17/2005 6:29:02 AM

7 Replies
37 Views

(page loaded in 0.489 seconds)


Reply: