Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Naming issue

Reply
Thread Tools

Naming issue

 
 
Martin Eisenberg
Guest
Posts: n/a
 
      12-16-2005
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.
 
Reply With Quote
 
 
 
 
Mateusz Loskot
Guest
Posts: n/a
 
      12-16-2005
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

 
Reply With Quote
 
 
 
 
Martin Eisenberg
Guest
Posts: n/a
 
      12-16-2005
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.
 
Reply With Quote
 
Mateusz Loskot
Guest
Posts: n/a
 
      12-16-2005
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

 
Reply With Quote
 
Martin Eisenberg
Guest
Posts: n/a
 
      12-17-2005
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.
 
Reply With Quote
 
homsan toft
Guest
Posts: n/a
 
      12-17-2005
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

 
Reply With Quote
 
Mateusz Loskot
Guest
Posts: n/a
 
      12-17-2005
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

 
Reply With Quote
 
Martin Eisenberg
Guest
Posts: n/a
 
      12-17-2005
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Naming issue: It is hard to keep it consistent Author #1 ASP .Net 8 08-12-2009 01:21 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Javax.naming Exception: name not found in naming service. Harman Java 1 07-28-2006 08:51 AM
Issue: The SqlDataSource control does not have a naming container wubin_98@yahoo.com ASP .Net 2 03-10-2006 10:55 PM
Network Naming John Williams Wireless Networking 4 10-01-2005 01:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57