By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,941 Members | 1,983 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,941 IT Pros & Developers. It's quick & easy.

Naming issue

P: n/a
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.
Dec 16 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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

Dec 16 '05 #2

P: n/a
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.
Dec 16 '05 #3

P: n/a
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

Dec 16 '05 #4

P: n/a
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.
Dec 17 '05 #5

P: n/a
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

Dec 17 '05 #6

P: n/a
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

Dec 17 '05 #7

P: n/a
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.
Dec 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.