Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Another name of type of iterator allowed or not?

Thread Tools

Another name of type of iterator allowed or not?

Victor Bazarov
Posts: n/a
Mateusz Loskot wrote:
> My major aim is to develop coding style as much consistent as
> possible. So, I'd like to avoid mutually exclusive rules and
> occurences like those:
> 1) Rule: Every type starts with capital letter
> 2) Next, I have my library strongly based on STL and I'd like to
> provide STL coherent interface so I have in one of my class:
> class A
> {
> public:
> typedef std::string::size_type size_type;
> size_type size() const;
> };
> And here size_type breaks the rule defined in 1).
> Yes, according to this rule in 1) I could write:
> typedef std::string::size_type SizeType;
> SizeType size() const;
> But, users of my library learn (from documentation etc.) that
> collection-like or collection composition classes in my library
> provide number of elements through size() function, just like STL
> std::vector or std::string does it and the type of return value is
> ....size_type but not ...SizeType.
> Simply, it breaks inconsistency, doesn't it?
> I hope I provide clear example now.

It is rather difficult to come up with a set of rules in which following
any one does not cause breaking another. Just think of the Three Laws
of Robotics. Something has to be superior. In your case, you can say

1. Naming convention shall be consistent with the rest of the used
source code (library source in the form of headers included)
2. Types shall be capitalized unless it violates rule 1.

In general, don't waste your time trying to come up with rules. Better
spend your time learning the existing rules, like those of the language.


Reply With Quote
Mateusz Loskot
Posts: n/a
As I said, I'm convinced and your comments are very instructive.
I like those 2 rules you've introduced
Mateusz Loskot

Reply With Quote

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
Why defining a constant in a method is not allowed but usingself.class.const_set is allowed? IƱaki Baz Castillo Ruby 13 05-01-2011 06:09 PM
Singleton: type name is not allowed C++ 3 02-26-2009 05:20 AM
Same name for a type and a method allowed? C++ 9 03-04-2008 09:07 AM
conversion from const type* to type* allowed? Michal Nazarewicz C Programming 13 01-05-2007 01:54 PM
type* name vs. type *name Sergei Gnezdov C Programming 5 03-29-2005 06:04 PM